{"id":78545,"date":"2016-06-01T00:01:21","date_gmt":"2016-06-01T07:01:21","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/?p=78545"},"modified":"2019-02-18T09:10:42","modified_gmt":"2019-02-18T16:10:42","slug":"retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-3","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-3\/","title":{"rendered":"Retrieve Azure Resource Manager virtual machine properties by using PowerShell \u2013 Part 3"},"content":{"rendered":"<p><strong>Summary<\/strong>: Identify properties for the operating system of a virtual machine.<\/p>\n<p>This blog post is part of a series about how to retrieve Azure Resource Manager virtual machine properties by using PowerShell. To get the most out of this series, read the posts in order.<\/p>\n<p>If you\u2019re new to PowerShell, you might want to first read the preceding five-part series about <a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/23\/work-with-the-azurerm-cmdlets-part-1\/\">how to work with Azure Resource Manager cmdlets<\/a>.<\/p>\n<ul>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/30\/retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-1\/\">Retrieve Azure Resource Manager virtual machine properties by using PowerShell \u2013 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/05\/31\/retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-2\/\">Retrieve Azure Resource Manager virtual machine properties by using PowerShell \u2013 Part 2<\/a><\/li>\n<li>Retrieve Azure Resource Manager virtual machine properties by using PowerShell \u2013 Part 3<\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/06\/02\/retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-4\/\">Retrieve Azure Resource Manager virtual machine properties by using PowerShell \u2013 Part 4<\/a><\/li>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/06\/03\/retrieve-azure-resource-manager-virtual-machine-properties-by-using-powershell-part-5\/\">Retrieve Azure Resource Manager virtual machine properties by using PowerShell \u2013 Part 5<\/a><\/li>\n<\/ul>\n<p>After you finish this series, move on to the next series to learn more about the Azure Resource Manager cmdlets.<\/p>\n<ul>\n<li><a href=\"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2016\/06\/06\/create-azure-resource-manager-virtual-machines-by-using-powershell-part-1\/\">Create Azure Resource Manager virtual machines by using PowerShell<\/a><\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\" \/> Can you show me how to identify the properties for the operating system so that I can duplicate a virtual machine?<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\" \/>\u00a0Honorary Scripting Guy, Sean Kearney, is here with a little more Azure and PowerShell for you. Today we\u2019re going to examine the properties that tell us the template to use for the operating system.<\/p>\n<p>Again, none of this is hidden in the portal. However, if you look, you won\u2019t see the exact details that PowerShell will want for virtual machines.<\/p>\n<p>In fact, when we look at the portal, it doesn\u2019t even identify the <u>version<\/u> of Linux. It just says \u201cLinux,\u201d which really isn\u2019t all that helpful.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSSG-060116.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78546\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1-HSSG-060116.png\" alt=\"Screenshot of the properties which indicate an operating system.\" width=\"619\" height=\"311\" \/><\/a><\/p>\n<p>As we did yesterday, we\u2019ll store the properties of the virtual machine in an object.<\/p>\n<p style=\"padding-left: 30px\"><code>$VM=Get-AzureRMVM \u2013Name HSG-Linux1 \u2013ResourceGroupName HSG-AzureRG<\/code><\/p>\n<p>The particular set of properties that we need are actually stored under a property known as <strong>StorageProfile<\/strong>.<\/p>\n<p style=\"padding-left: 30px\"><code>$VM.StorageProfile<\/code><\/p>\n<p>Buried within the <strong>StorageProfile<\/strong> object is a <u>very<\/u> useful property named <strong>ImageReference<\/strong>.<\/p>\n<p style=\"padding-left: 30px\"><code>$VM.StorageProfile.ImageReference<\/code><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSSG-060116.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-78555\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/2-HSSG-060116.png\" alt=\"Screenshot that shows the publisher, offer, SKU, and version information.\" width=\"599\" height=\"106\" \/><\/a><\/p>\n<p>By using PowerShell, I can identify three of the key pieces that I will need for a virtual machine. It\u2019s also important to note that this is common to both Linux and Windows deployments.<\/p>\n<p>After I store the publisher, offer, and SKU properties, I can use this to obtain the data that I will need next week to create a virtual machine: the operating system image. We use the <strong>Get-AzureRMVMImage<\/strong> cmdlet for this.<\/p>\n<p>To get the images, we need four pieces of Information.<\/p>\n<ul>\n<li>Publisher<\/li>\n<li>Offer<\/li>\n<li>SKU<\/li>\n<li>Location<\/li>\n<\/ul>\n<p>We have the first three:<\/p>\n<p style=\"padding-left: 30px\"><code>$Publisher=$VM.StorageProfile.ImageReference.Publisher\n$Offer=$VM.StorageProfile.ImageReference.Offer\n$Sku=$VM.StorageProfile.ImageReference.Sku<\/code><\/p>\n<p>The location is just another available property from the virtual machine. It\u2019s not even buried.<\/p>\n<p style=\"padding-left: 30px\"><code>$Location=$VM.location<\/code><\/p>\n<p>With this information, we can now access a list of virtual machine images that can be used to create a twin of this virtual machine that uses the same operating system.<\/p>\n<p style=\"padding-left: 30px\"><code>Get-AzureRmVMImage -PublisherName 'Canonical' -Offer 'UbuntuServer' -Skus '14.04.4-LTS' -Location 'eastus'<\/code><\/p>\n<p>Oh, how do we sort <u>this<\/u> mess out? It appears that we have too many versions to choose from. If you\u2019d like the latest one, we can sort by the version number.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSSG-060116.png\"><img decoding=\"async\" class=\"alignnone wp-image-78565 size-full\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3-HSSG-060116.png\" alt=\"Screenshot that shows versions of Ubuntu images.\" width=\"814\" height=\"104\" \/><\/a><\/p>\n<p style=\"padding-left: 30px\"><code>Get-AzureRmVMImage -PublisherName 'Canonical' -Offer 'UbuntuServer' -Skus '14.04.4-LTS' -Location 'eastus' | Sort-Object Version<\/code><\/p>\n<p>Then, we can grab the newest one from the bottom of the pile!<\/p>\n<p style=\"padding-left: 30px\"><code>(Get-AzureRmVMImage -PublisherName 'Canonical' -Offer 'UbuntuServer' -Skus '14.04.4-LTS' -Location 'eastus' | Sort-Object Version)[-1]<\/code><\/p>\n<p>Pretty neat, eh?<\/p>\n<p>Come on by tomorrow when we discuss how to identify the resource group and other properties that are attached to the virtual machine!<\/p>\n<p>I invite you to follow the Scripting Guys on and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to them 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.<\/p>\n<p>Until then, always remember that with Great PowerShell comes Great Responsibility.<\/p>\n<p><strong>Sean Kearney\n<\/strong>Honorary Scripting Guy\nCloud and Datacenter Management MVP<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Identify properties for the operating system of a virtual machine. This blog post is part of a series about how to retrieve Azure Resource Manager virtual machine properties by using PowerShell. To get the most out of this series, read the posts in order. If you\u2019re new to PowerShell, you might want to first [&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":[568,685,641],"tags":[56,154,45],"class_list":["post-78545","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hey-scripting-guy","category-scripting-techniques","category-windows-powershell","tag-guest-blogger","tag-sean-kearney","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Identify properties for the operating system of a virtual machine. This blog post is part of a series about how to retrieve Azure Resource Manager virtual machine properties by using PowerShell. To get the most out of this series, read the posts in order. If you\u2019re new to PowerShell, you might want to first [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/78545","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=78545"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/78545\/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=78545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=78545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=78545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}