Using Azure Automation: Part 3


Summary: Learn how to access Azure Automation assets within a runbook.

Honorary Scripting Guy, Sean Kearney, is here today to battle robots, aliens, and…

…No, wait, sorry. My brain lapsed from watching an old rerun of Lost in Space.

This is the third post in a five-part series. To catch up, read:

Today I will continue showing you how to get up and running with Azure Automation with a simple project of having a runbook to shutdown virtual machines in Azure.

Our previous runbook with the fully exposed credentials and a clear-text password looked like this (I sense far too many security specialists shaking their heads at this):

Image of script

We can mitigate all of this silliness now by inserting the asset from the Azure Automation that we created yesterday.

This is done by choosing the place in the runbook where we would like the asset, clicking Setting, and choosing Insert to select an asset. In the following example, I created a new line for assigning the $cred object that will be inserted in the code from Azure Automation:

Image of script

When I click Insert, a wizard appears, which allows us to choose the asset. It will also automatically build the needed cmdlet to access the asset.

In the following example, we are going to access our newly created object called AzureManagementCredentials. (Aren't you glad we gave it a useful name instead of something like TribbleFodder?)

Image of menu

When we return to the runbook, we'll see a new line of code appended to the $Cred= portion:

Image of script

We now delete the two lines of code in the previous runbook that used the UserID and Password to get this result.

Image of script

At this point, we click the Test button to confirm that everything is working properly in our script.

It seems to work, but we have nothing to tell us what, why, or how something happened? Come back tomorrow, and I'll show you some simple things to finish up this runbook and promote it in production!

I invite you to follow The Scripting Guys on Twitter and Facebook. If you have any questions, send an email to The Scripting Guys at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then remember eat your cmdlets every day with a taste of creativity.

Sean Kearney, Windows PowerShell MVP and Honorary Scripting Guy

Comments (4)

  1. @Alex

    You are absolutely correct and you certainly know your PowerShell! I was in the midst of my editing that screenshot contained some code from an earlier copy/paste.

    The line

    $Result=Stop-AzureVM -name $_.Name -servicename $_.Servicename -Force

    Should read

    $Result=Stop-AzureVM -name $VM.Name -servicename $VM.Servicename -Force

    Thanks for catching it!
    Sean
    Honorary Scripting Guy
    —- and fellow who actually SHOULD have had that extra cup of coffee during typing 😉

  2. alex says:

    The $_.Name in the last screenshot within the foreach ($VM in ..) will probably not work?

  3. pete says:

    You might also point out that the credentials need to be Organizational credentials. Microsoft account credentials won’t work. Good blog on the work around here

    http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/

Skip to main content