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.
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
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
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'
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!
Categories: Cyber Security, Microsoft Azure, PowerShell, Windows Server
Hi, which is the command to check the vm in the variable list please? thanks in advance
Really useful, Thank You!!
LikeLiked by 1 person