Get-AzureRmVM需要名称参数吗?

时间:2017-11-14 22:56:00

标签: azure azure-powershell azure-automation azure-cloud-shell

如果我从Azure云shell运行此powershell命令,它会正常运行,并为我提供指定资源组中所有VM的列表:

  

Get-AzureRmVM -ResourceGroupName“MyGroup”-Status

如果我在自动化帐户的Runbook中执行它,我会收到错误;

  

Get-AzureRmVM:由于一个或多个缺失而无法处理命令   必填参数:名称。在TestAutomationAccount-Job-StartVM:20 char:20   +       + CategoryInfo:InvalidArgument:(:) [Get-AzureRmVM],ParameterBindingException       + FullyQualifiedErrorId:MissingMandatoryParameter,Microsoft.Azure.Commands.Compute.GetAzureVMCommand

我正在尝试获取资源组中的虚拟机列表,并且无法弄清楚为什么会出现明显的行为差异。

1 个答案:

答案 0 :(得分:1)

在Azure自动化Runbook中运行时,我能够为Get-AzureRmVM cmdlet重现相同的异常。

此问题的根本原因仅在于Azure自动化环境和Azure Cloud Shell(PowerShell)环境中Get-AzureRmVM cmdlet的版本不匹配

Get-AzureRmVM cmdlet位于 AzureRm.Compute PowerShell模块下。

当我使用以下cmdlet在Azure自动化环境中获取 AzureRm.Compute 的版本时。

Get-Module -ListAvailable -Name AzureRm.Compute -Refresh

Azure Automation环境的版本为 1.2.1 ,如下所示。

enter image description here

当我使用以下cmdlet在Azure Cloud Shell(PowerShell)会话中获取 AzureRm.Compute 的版本时。

Get-AzureRmCommand Get-AzureRmVM

Azure Cloud Shell(PowerShell)环境的版本为 3.4.1 ,如下所示。

enter image description here

因此,我认为这两个环境中的 AzureRm.Compute 模块版本不匹配解释了Get-AzureRmVM cmdlet的不同行为和参数期望。

希望这有帮助。

<强>附录: 如果您希望获得与Get-AzureRmVM cmdlet相同的Azure Cloud Shell环境体验,则可以转到Azure自动化帐户中的“模块”部分,选择AzureRm.Compute模块并将其更新为版本与Azure Cloud Shell环境相同。

enter image description here