gpt4 book ai didi

azure - Get-AzureRmVM 需要名称参数吗?

转载 作者:行者123 更新时间:2023-12-02 23:31:17 26 4
gpt4 key购买 nike

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

Get-AzureRmVM -ResourceGroupName "MyGroup" -Status

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

Get-AzureRmVM : Cannot process command because of one or more missing mandatory parameters: Name. At TestAutomationAccount-Job-StartVM:20 char:20 + + CategoryInfo : InvalidArgument: (:) [Get-AzureRmVM], ParameterBindingException + FullyQualifiedErrorId : MissingMandatoryParameter,Microsoft.Azure.Commands.Compute.GetAzureVMCommand

我正在尝试获取资源组内的虚拟机列表,但无法弄清楚为什么行为存在明显差异。

最佳答案

在 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 自动化环境版本是 1.2.1,如下所示。

enter image description here

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

Get-AzureRmCommand Get-AzureRmVM

我获得的 Azure Cloud Shell (PowerShell) 环境版本是 3.4.1,如下所示。

enter image description here

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

希望这有帮助。

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

enter image description here

关于azure - Get-AzureRmVM 需要名称参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47296633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com