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


Open a URL using Task Scheduler

I use this script when I need a specific web page to open in the background, for example updating Dynamic DNS or other websites that I can open to force them to process.

Create a .vbs script using the following

Sub openwebsite(w)
On Error Resume Next
Dim objRequest
Set objRequest = CreateObject(“Microsoft.XMLHTTP”)
objRequest.open “POST”, w , false
Set objRequest = Nothing
End Sub

openwebsite “http://mywebsite
openwebsite “http://anotherwebsite

Add a new scheduled task to execute the .vbs script repeating regularly and running as the “SYSTEM” account