Azure

Microsoft Azure: How to exclude VMs from the Auto Start-Stop schedule with PowerShell

Last weekend I successfully created an automation account in Azure to auto start-stop my Azure VMs as described here:  Start/Stop VMs during off-hours solution in Azure Automation. Right after that I realized that I forgot to exclude some VMs from this routine.

Unbenannt.PNG

I have configured tons of new resources but how to make changes after creation of that resources, especially how can I exclude some of my VMs? As almost always, PowerShell is the right way to do such things.

The excluded VMs are stored in the External_ExcludeVMNames variable. The screen below shows the variable using the PowerShell cloud shell.


Get-AzAutomationVariable -Name External_ExcludeVMNames -AutomationAccountName AutomateStartStop -ResourceGroupName Group1

Unbenannt.PNG

Note that the Automation account name and resource group name must be specified in the command. To find out your automation account and resource group name run


Get-AzAutomationAccount

Get-AzResourceGroup

Which brings me to the point. I want to exclude the computers dc02 and cl01 from the start-stop schedule. Here is the command to do just that.


Get-AzAutomationVariable -Name External_ExcludeVMNames -AutomationAccountName AutomateStartStop -ResourceGroupName Group1 | Set-AzAutomationVariable -Value 'dc02,cl01'

Unbenannt.PNG

We’re done. All virtual computers will be started and stopped according to a fixed schedule, except dc02 and cl01.

See you next time with PowerShell!

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

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