This script and workflow is designed to either start or stop a group of VM's in a Resource Group in Azure. The script/workflow has 3 parameters:
This defaults to AzureRunAsConnection which is the default connection name Azure creates when running through the Azure Automation Account wizard.
This parameter is mandatory, and is the name of the ResourceGroup you wish to have the runbook run against.
This is going to be one of two values PowerState/running or PowerState/deallocated. This will be the state that we want to enforce on the vm's in the Resource Group.
- PowerState/running, will start stopped vm's.
- PowerState/deallocated will stop running vm's.
Create Azure Run As account
This is a toggle, leaving it at the default will create the SPN in the Azure AD that will allow the PowerShell scripts/workflows to use.
After the automation account is created it will show up in the Portal. If you open it up and click Assets, and then Connections you will see two connections the SPN connection for ARM deployments and a Certificate for Classic (v1) deployments. The scripts/workflows will use the default name for SPN as most of these will be targeted at ARM deployments.
If you have an Automation Account already, you can create the SPN yourself in the Portal. You will need the TenantID and SubscriptionID, and the ApplicationID and Certificate Thumbprint are generated for you by Azure when you create the SPN.
Now that the Automation Account is setup all that's left is to create your runbooks. Back in your Automation Account blade, you can click on Runbooks and then click Add a runbook. At this point you can either import a runbook, or create a new runbook. We will walk through creating a new runbook, you will need to provide a Name, a Description and then choose a Runbook Type.