2
votes

If I run this powershell command from an Azure cloud shell it executes fine and gives me a list of all VMs in the specified resource group:

Get-AzureRmVM -ResourceGroupName "MyGroup" -Status

If I execute it in a runbook from an automation account I get an error;

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

I'm trying to get a list of VMs within a resource group, and can't figure out why the apparent difference of behavior.

1

1 Answers

3
votes

I am able to reproduce the same exception for the Get-AzureRmVM cmdlet when running in the Azure Automation runbook.

The root cause to this issue is simply due to the version mismatch of the Get-AzureRmVM cmdlet in the Azure Automation environment and Azure Cloud Shell (PowerShell) environment.

The Get-AzureRmVM cmdlet is under the AzureRm.Compute PowerShell module.

When I use the below cmdlet to get the version of AzureRm.Compute in the Azure Automation environment.

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

The version I get is 1.2.1 for the Azure Automation environment as shown below.

enter image description here

When I use the below cmdlet to get the version of AzureRm.Compute in the Azure Cloud Shell (PowerShell) session.

Get-AzureRmCommand Get-AzureRmVM

The version I get is 3.4.1 for the Azure Cloud Shell (PowerShell) environment as shown below.

enter image description here

Hence I believe the AzureRm.Compute module version mismatch in these 2 environments explained the different behavior and parameters expectation for the Get-AzureRmVM cmdlet.

Hope this helps.

Addendum: If you want to get the same experience for the Get-AzureRmVM cmdlet as it is in the Azure Cloud Shell environment, you can go to the Modules section in your Azure Automation account, select the AzureRm.Compute module and update it to the version to be the same as the Azure Cloud Shell environment.

enter image description here