尝试通过Windows Server 2019 VMAzure上的串行控制台通过Powershell命令启用Hyper-V时无法访问

问题描述

我在Azure中使用Windows Server 2019数据中心映像创建了一个VM。根据公司政策,我们不允许拥有公共IP和端口。访问虚拟机的唯一方法是使用串行控制台。

我能够在串行控制台中运行PowerShell。但是,我遇到了访问问题。

错误

PS C:\windows\system32> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
Enable-WindowsOptionalFeature : Win32 internal error "Access is denied" 0x5
occurred while reading the console output buffer. Contact Microsoft Customer
Support Services.
At line:1 char:1
+ Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (:) [Enable-WindowsOptionalFeature],HostException
    + FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.dism.Commands.Enable
   WindowsOptionalFeatureCommand

我尝试elevate the Powershell prompt,但没有运气。我创建的帐户应具有管理员权限。我想知道有什么方法可以使它正常工作。预先感谢。

解决方法

我认为Server 2019数据中心映像存在一些限制,因为我也遇到相同的错误,但它在Server 2016数据中心上有效,请参见this

enter image description here

作为一种解决方法,如果未为Azure VM分配公共IP地址,则建议通过run command在Azure VM中运行PowerShell脚本。该功能使用虚拟机(VM)代理在Azure Windows VM中运行PowerShell脚本。有关在Windows VM中运行脚本的更多信息,请参考this document

例如,您可以通过PowerShell脚本启用hyper-v

Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart

然后通过Invoke-AzVMRunCommand cmdlet调用脚本以在Azure VM上运行PowerShell脚本。该cmdlet希望在-ScriptPath参数中引用的脚本对于该cmdlet的运行位置是本地的。

enter image description here