{"id":5781,"date":"2015-06-03T00:01:00","date_gmt":"2015-06-03T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2015\/06\/03\/using-azure-automation-part-3\/"},"modified":"2019-02-18T09:47:37","modified_gmt":"2019-02-18T16:47:37","slug":"using-azure-automation-part-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/using-azure-automation-part-3\/","title":{"rendered":"Using Azure Automation: Part 3"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary: <\/b><span style=\"font-size:12px\">Learn how to access Azure Automation assets within a runbook.<\/span><\/p>\n<p>Honorary Scripting Guy, Sean Kearney, is here today to battle robots, aliens, and&hellip;<\/p>\n<p>&hellip;No, wait, sorry. My brain lapsed from watching an old rerun of <i>Lost in Space<\/i>.<\/p>\n<p>This is the third post in a five-part series. To catch up, read:<\/p>\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/using-azure-automation-part-1\/\" target=\"_blank\">Using Azure Automation: Part&nbsp;1<\/a><\/li>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/scripting\/using-azure-automation-part-2\/\" target=\"_blank\">Using Azure Automation: Part 2<\/a><\/li>\n<\/ul>\n<p>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.<\/p>\n<p>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):<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/3441.1.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/3441.1.PNG\" alt=\"Image of script\" title=\"Image of script\" \/><\/a><\/p>\n<p>We can mitigate all of this silliness now by inserting the asset from the Azure Automation that we created yesterday.<\/p>\n<p>This is done by choosing the place in the runbook where we would like the asset, clicking <b>Setting<\/b>, and choosing <b>Insert<\/b> to select an asset. In the following example, I created a new line for assigning the <b>$cred<\/b> object that will be inserted in the code from Azure Automation:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/0334.2.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/0334.2.PNG\" alt=\"Image of script\" title=\"Image of script\" \/><\/a><\/p>\n<p>When I click <b>Insert<\/b>, a wizard appears, which allows us to choose the asset. It will also automatically build the needed cmdlet to access the asset.<\/p>\n<p>In the following example, we are going to access our newly created object called <b>AzureManagementCredentials<\/b>. (Aren&#039;t you glad we gave it a useful name instead of something like <b>TribbleFodder<\/b>?)<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/4621.3.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/4621.3.PNG\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>When we return to the runbook, we&#039;ll see a new line of code appended to the <b>$Cred=<\/b> portion:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/6180.4.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/6180.4.PNG\" alt=\"Image of script\" title=\"Image of script\" \/><\/a><\/p>\n<p>We now delete the two lines of code in the previous runbook that used the <b>UserID<\/b> and <b>Password<\/b> to get this result.<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/5-2.PNG\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/5-2.PNG\" alt=\"Image of script\" title=\"Image of script\" \/><\/a><\/p>\n<p>At this point, we click the <b>Test<\/b> button to confirm that everything is working properly in our script.<\/p>\n<p>It seems to work, but we have nothing to tell us what, why, or how something happened? Come back tomorrow, and I&#039;ll show you some simple things to finish up this runbook and promote it in production!<\/p>\n<p>I invite you to follow The Scripting Guys on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send an email to The Scripting Guys at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then remember eat your cmdlets every day with a taste of creativity.<\/p>\n<p><b>Sean Kearney, <\/b>Windows PowerShell MVP and Honorary Scripting Guy<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to access Azure Automation assets within a runbook. Honorary Scripting Guy, Sean Kearney, is here today to battle robots, aliens, and&hellip; &hellip;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: Using Azure Automation: [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[583,56,154,549,45],"class_list":["post-5781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-azure-automation","tag-guest-blogger","tag-sean-kearney","tag-series","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to access Azure Automation assets within a runbook. Honorary Scripting Guy, Sean Kearney, is here today to battle robots, aliens, and&hellip; &hellip;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: Using Azure Automation: [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=5781"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/5781\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=5781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=5781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=5781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}