PowerShell Workflow Script To Stop VM’s In A Resource Group
Recently I needed to make sure that all the VM’s in a given resource group were stopped, and so I looked around the Runbooks available to download from the Azure Marketplace. Some of these were ridiculously complex: one was over 500 lines long! Just to stop a VM!
Naturally there is a need to setup: we need to get the names of the VM’s in the Resource Group and, if they are running, then stop them. However the command to stop a VM is straightforward: “Stop-AzureRmVM”, followed by the name of the VM and the resource group. Quite frankly I’m impressed that people have managed to over-engineer invoking this function.
So here is a proper noddy script that will stop all VM’s that are running in a resource group. No fancy dan stuff here. Clearly this script doesn’t take into account any of the useful assets that you can use in a Runbook, but for the time being at least, where you have only a few resource groups to manage, this script will suffice.