This tip addresses a problem you are sure to have if attempting to work with the Azure Resource Manager (ARM) PowerShell cmdlets within Azure Automation in May 2015. I should preface by sharing that I believe this situation may change as the story evolves with Azure Resource Manager (ARM) and PowerShell, as the Azure Automation team may still be working on optimizing the user experience.
When you attempt to use Get-AzureVM and some other cmdlets in the ARM PowerShell module, they fail due to incorrect parameters. If like me, you test your runbooks in Visual Studio or the PowerShell ISE before copying into Azure Automation, this error will be confusing.
There are two issues here:
- The ARM PowerShell module is not present in Azure Automation by default.
- The ARM cmdlets (which support much of the Azure IaaS v2 functionality announced at Build and MS Ignite, such as JSON deployment templates) and the Azure Service Management cmdlets (used in most Azure IaaS v1 operations) functionality have cmdlets with the same names, but different parameters.
Step 1: Zip and Import the Azure Resource Manager PowerShell Module
If you installed the latest Azure PowerShell cmdlets, the default path on a 64-bit OS (as of May 2015) is shown below.
C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager
Zip up this directory and all the files and folders in it, which will include AzureResourceManager.psd1. As you zip the folder, the file name should default to AzureResourceManager.zip.
Step 2: Upload the Module to Azure Automation
To upload the ARM PowerShell module in the Azure Preview Portal, which is designed to support the new Azure IaaS v2 capabilities, perform the following steps:
1) Login to the Azure Preview Portal at https://portal.azure.com
2) Select Browse from the left navigation pane.
3) Then select Automation Accounts, followed by your Azure Automation account.
4) Next, click on Assets, then Modules
5) Click on Add a module and browse to the zip file containing the ARM module you zipped in the previous task.
6) Select Open, then OK to upload.
Give Azure Automation a few minutes to consume the module and extract the cmdlets. You will see a message in the Notifications area when the operation is complete.
Once you upload the ARM PowerShell module, you have a new problem: the ARM and Azure Service Management (ASM) PowerShell modules have quite a few key cmdlets with the same names. Since the ASM cmdlets are present by default, those cmdlets seem to be called first, even after you have uploaded the ARM module to your Azure Automation subscription.
Workaround: Specify the path when calling ARM cmdlets
This simply means that when you wish to call a cmdlet in the ARM PowerShell Module, you must specify the path, like so
So to call Start-AzureVM from the ARM PowerShell module, you would type AzureResourceManager\Get-AzureVM
To see a working illustration of this concept, you can view and use a sample runbook I provided in the Microsoft Technet Gallery at the URL below:
I hope this helps. If you’ve encountered other challenges working with the ARM cmdlets and Azure IaaS v2 in Azure Automation, I would be interested to hear about your experience in the Comments section below.