Automating Azure VM Start/Shutdown with PowerShell Runbook and User-Managed Identity

Hey Everyone, 

I wrote a Powershell runbook to automate the start / shutdown of Azure VMs using an user-managed identity, you can create an automation account in Azure if you don’t have one already and add this runbook , schedule the runbook to run when you want to shutdown and start the VM

You can deallocate VMs when they’re not in use using this runbook to optimize the Azure cost

Also, if you already have a runbook which uses a Run as account, you should migrate to user-managed identity since Azure automation Run As Account will retire on September 30, 2023.

Make sure to replace the <ClientId of USI> field in below code with your manage identity’s Client ID, also make sure the you have virtual machine contributor role or higher permission assigned to the managed identity

You can download the workbook here

Add a Comment

Your email address will not be published. Required fields are marked *