Azure Automation – getting started
Azure Automation allows Azure administrators to run PowerShell and other scripts against an Azure subscription. They provide several benefits versus running the same scripts from the user desktop computer including:
- Scripts run in Azure and are not dependent on the end-user desktop
- Scripts are highly available by design.
- Scheduling is a built-in feature
- Authentication is streamlined for both classic ASM and current ARM resources
To get started with Azure Automation;
- Create an Azure Automation account
- Install needed PowerShell modules
- Create, run, test, schedule scripts
Create an Azure Automation account
In the current portal, Create Resource > Monitoring and Management > Automation > Create
In the ‘Add Automation Account’ blade enter/select a name for the Automation Account, Azure Subscription, Resource Group, and Azure Location
Azure will take a few minutes to create the automation account and associated objects.
We can now run scripts against the Azure subscription selected above. Here are some examples:
Create a test script
In the Automation Account blade, click Runbooks
Click ‘Add a runbook’ link on the top to create a new runbook of type PowerShell
Azure creates the runbook/script, and opens the ‘Edit PowerShell Runbook’ blade
Type in the desired command, click Save, then ‘Test pane’
In the ‘Test’ blade, click ‘Start’. Azure will queue and execute the script
- This is not like the PowerShell ISE. There’s no auto-completion for one thing.
- If Azure comes across a bad command, it will try to execute THE ENTIRE SCRIPT repeatedly, and is likely to get stuck.
- This shell does not support user interaction. So, any cmdlet that would typically require a user confirmation/interaction of any type will fail. For example, Install-Module cmdlet will fail since it requires user approval/interaction to install PowerShellGet.
Install needed modules
To see available modules click ‘Modules’ in the Automation Account blade
Click ‘Browse Gallery’ on top and search for the desired module
These modules come for the Microsoft PowerShell Gallery.
Click on the desired module, view its functions, and click Import to import it to this automation shell
Now that the module is imported, we can use it in scripting in this particular automation shell: