Powershell – Azure : Script to start or shut down multiple VMs

automationazurepowershellvirtual-machines

Is it possible to write and save some kind of script that launches azure powershell, then authenticate azure subscription then start/shutdown multiple VMs in one step?

I have 5 VMs that I use regularly at specific unscheduled time, so I don't want do the steps of logging into azure portal, starting VMs one by one then do the same to shut them down, at every time I need to use them! I need to automate this process.

Best Answer

Definitively, you should use Azure Automation to run on schedule a PowerShell Script to shutdown or start your VM in Azure. It is already well documented on Microsoft Web site.

Here are 3 links that explains step by step how to do this

Stop Azure Virtual Machine using Azure Automation Runbook https://gallery.technet.microsoft.com/scriptcenter/Stop-Azure-Virtual-Machine-0b1fea97

Shutting down a Azure VM with Azure Automation http://blogs.technet.com/b/georgewallace/archive/2014/11/05/shutting-down-a-azure-vm-with-azure-automation.aspx

Using Azure Automation to run VMs during office hours only https://blogs.endjin.com/2015/01/using-azure-automation-to-run-vms-during-office-hours-only/

Regards

Stanislas