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.

Advertisement

By:

Posted in:


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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: