Azure Automation | Start | Stop | Virtual machines.

Azure automation is a cool feature that can use to automate the creation, monitoring, deployment and management of cloud resources in your Microsoft Azure subscription using a highly-available workflow execution engine.

It’s a really cool feature, but when it’s first released, all the PowerShell run books have to use the certificate based authentication. And there should be a separate run book required to publish to access this certificate based authentication. But with new updated azure automation, its support PowerShell credential based authentication, which will enable to write PowerShell run books much easier.

This article describe how to automate the VM start and stop (deallocation) using PowerShell run books by credential level authentication.


  1. Create an Azure Administrator account in the Azure active directory to run Azure automation run books.
    1. Create a Azure Active Directory User
      1. Select Active Directory on right side panel
      2. Select the Azure active directory
      3. Create new user (Automation user)
    2. Make this user as a Co-Administrator
      1. Select Settings from panel
      2. Select administrators
      3. Click ADD user and give the email address of the user account that created. (Automation user)


  2. Create Automation Account
    1. Click the automation tab
    2. Click the plus sign to create a new automation account.


  3. Define credential for azure automation account
    1. Click the newly created automation account
    2. Go to assets tab
    3. Click add settings and select ADD credentials.
    4. In define credentials page select PowerShell credentials for credential type


  4. Create VM start Run Book.
    1. Click the run book tab
    2. Click new (plus sign)
    3. Automation – runbook – quick create, give the runbook name as VM start.
    4. Click edit runbook or click on the Run book – Autor – Draft
    5. Type the following powershell script

      workflow Get-VMStart


      $Cred = Get-AutomationPSCredential –Name

      Add-AzureAccount -Credential $Cred

      Select-AzureSubscription -SubscriptionName “Visual Studio Premium with MSDN”

      Start-AzureVM -ServiceName “VM01” -Name “VM01” -force



      • In automation ps credential name, type the account name that defined earlier.
      • Subscription name, you can find out from the portal – settings – subscription
      • AzureVM – Service name, is the cloud service name for the VM
      • AzureVM – name , is the VM name.
  5. Create a VM Stop runbook
    1. Use the same steps with the following script (use a new runbook)
      workflow Get-VMStop


      $Cred = Get-AutomationPSCredential –Name

      Add-AzureAccount -Credential $Cred

      Select-AzureSubscription -SubscriptionName “Visual Studio Premium with MSDN”

      Stop-AzureVM -ServiceName “VM01” -Name “VM01”


  6. Click Test to run the Runbook.

you can schedule this runbooks to run any preferred time

Hope this is helpful



Leave a Reply

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

You are commenting using your 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