In this blog post, we’ll guide you through the process of installing a PowerShell module in Azure Automation.
Azure Automation is a powerful cloud-based service that allows you to automate frequent, time-consuming, and error-prone cloud management tasks. One of the critical aspects of Azure Automation is the use of PowerShell modules, which provide a range of cmdlets for managing and automating various Azure services. In this blog post, we’ll guide you through the process of installing a PowerShell module in Azure Automation using the New-AzAutomationModule cmdlet.
Get Started
Open PowerShell and run the following command to sign in to your Azure account:
Connect-AzAccount
If you have multiple subscriptions, choose the one you want to use for Azure Automation with the following command:
Select-AzSubscription -SubscriptionId <Your-Subscription-Id>
Create a new Azure Automation account (Optional)
New-AzAutomationAccount -ResourceGroupName <Resource-Group-Name> -Name <Automation-Account-Name> -Location <Location>
PowerShell Code
Now that you’re connected to your Azure account and have your Azure Automation account set up, you can install the desired PowerShell module using the New-AzAutomationModule cmdlet. In this example, we’ll install the “Az. Compute” module.
Note: The prerequisite to install the Compute module is Az. Accounts, so make sure it exists, or you install it first.
Note: Replace <Resource-Group-Name>
and <Automation-Account-Name>
with the appropriate values for your environment.
$moduleName ="Az.Compute"
$moduleVersion = "5.5.0"
$AutomationAccountName="Automation-account"
$rg="RG-Name"
New-AzAutomationModule -AutomationAccountName $AutomationAccountName -ResourceGroupName $rg `
-Name $moduleName -ContentLinkUri "https://www.powershellgallery.com/api/v2/package/$moduleName/$moduleVersion" -verbose
To confirm that the module was installed successfully, run the following command:
Get-AzAutomationModule -ResourceGroupName <Resource-Group-Name> -AutomationAccountName <Automation-Account-Name> -Name "Az.Compute"