Executing Scripts in Azure

It is useful to do various tasks from Azure. Excellent places to use this are to shut down specific servers overnight and restart in the morning to conserve consumption.

It is currently free for the first 500 minutes (job time) usage per month otherwise there is a small charge http://azure.microsoft.com/en-us/pricing/details/automation/

From the ACTIVE DIRECTORY module create a new user for the specific purpose of scripting

From the AUTOMATION module create a new Automation account for the relevant (don’t currently have North Europe for UK so have to execute this from the West Europe datacentre)

Open the new Automation account, from the ASSETS tab and then ADD SETTING to add the script user credentials for scripting

Select the RUNBOOKS tab, and add a new Runbook

Open the Runbook and use the following script

workflow automation-startup

$AutomationCredential = “scriptuser” #Credential used for authentication
$AzureSubscription = “Azure in Open” #Name of Azure subscription

$Cred = Get-AutomationPSCredential -Name $AutomationCredential

# Connect to Azure (ignore output)
$output = Add-AzureAccount -Credential $Cred

# Select subscription
Select-AzureSubscription -SubscriptionName $AzureSubscription
get-azurevm -service myservice -name myvm | start-azurevm

Publish the Runbook

Finally, Setup a convenient Schedule
If planning weekdays only, you will need to setup a schedule for each day and have it repeat every 7 days


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s