Ignoring VM’s with Stop Start Automation tasks in Azure

Thanks for yesterdays positive comments/questions and retweets.  To follow up after yesterdays post on creating Automated tasks in Azure we will modify the scripts and see what has happened.

Firstly to answer a question, yes you can ignore certain servers if they need to remain on or off.  The only issue I see is if a server is created and to be ignored by this script you will need to update the script each time another server is added to your Azure subscription.

Can you just use group memberships? @Simonster

Let’s change my scripts so Win10Az remains on or off, and must be stopped/started manually (normally).  So go back to Automation, stop script, author, draft, edit, change this line from

Get-AzureVM | where{$_.status -like ‘Stopped*’ } | Start-AzureVM

to

Get-AzureVM | where{$_.status -like ‘Stopped*’ -and $_.Name -ne ‘Win10Az’} | Start-AzureVM

This is highlighted in the screen grab below.

11

I ran the stop script and confirmed that only my BenWin10 server powered off.

I then added a similar line of code for my starting script, which you can see below.  I also selected the Start button on this screen.

12

Then once the start script had finished (90 seconds) I went back to my Virtual Machines view and as below you could see that only BenWin10 was starting up.  Win10Az was ignored when either script ran.

13

 

One last point, below is a screen shot of my scripts dashboard, from here you can easily see when the servers were on or off.  This is a great view to ensure your script is working as excepted.

14

Thanks

profile pic Aaron Whittaker @AaronW2003

 

Advertisements