Deallocate Azure VMs with Azure Devops – Scheduled VM shutdown.

Having been inspired by Gregor Suttie’s post ‘Replacing Azure Automation using Azure CLI and Azure Devops‘ I decided to do something similar with Powershell. My requirement was to power off VMs with a certain tag and value at a certain time.

The PowerShell for this is fairly simple:

Get-AzVM | Where-Object {$_.tags[‘shutDown’] -eq “19:00”} | Stop-AZVM -Force

I then created build pipeline in Azure Devops and added an ‘Azure PowerShell (Preview)’ task to the pipeline. This pipeline is scheduled to run every day at 19:00.

Expanding on this I could easily create a power on version of the pipeline as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s