Scheduling Azure Virtual Machine (VM) Startup With Azure Automation And Tags
Think you can do better? Show us!
I personally don’t trust automation and prefer doing everything manually but for some reason, Matt does not. He’d rather schedule things ahead of time like starting up Azure virtual machines. Lazy. And he’s also assigning tags so he doesn’t have to manually choose them too! This guy’s laziness just takes the cake.
In order to schedule Azure VM start up with Azure automation, and tags. We're going to need a couple of things. First, I'm going to need is an automation account in Azure Automation that needs to be set up beforehand. The next thing we're going to need is some virtual machines in order to start up and tag. We get to our virtual machines. Select a couple of the virtual machines say 02 and 03 here. Scroll up to the top to assign tags. give them a tag called startup time. Time is going to be called 6 AM start. Click on assign. And that will assign the tags to the VM's so we go back to our Azure Automation account. We need to create a runbook. Scroll down to run books. And click on add a runbook. And create a new run book. Going to call this scheduled startup and a runbook type is going to be powershell. Once the Runbook has created click on edit. I will have a blank blade here ready for the code. So if we go to ISE will see a few lines of code here first 2 lines of code are just connecting to the Azure Automation account. And the third line gets all of the Azure RM. VM's where the tag is like 6 AM start. All of those VMS on the fourth line and pipes them into start as your RM VM and a final line of code just outputs the names of the VMs that we just started. So we copy all of that code. Paste into our run book. And click on save. If we click on the test pain. Go to start. The book should start. Run book is completed. We go over to our virtual machines, we should see machines 0203, started and running. There we go. So the last thing we need to do is go back to our automation account. Find R run book. Click on the run book. Going to edit. I click on publish. Once the run book is published will see a schedule button at the top here. Click on that and link schedule to our run book. Create a new schedule. Going to call this. Start up 6 AM. Going to start it tomorrow. At 0600 hours. And make it recur every one day. Click on create. There we go OK. I went to run book if we go to schedules. You should see it as a schedule. Against our run book. And tomorrow at 6 AM. Those virtual machines that have got the tag against them will start up.