Extract Azure VM windows server 2012 and 2012 R2 VM's list with license policy

Jayesh Sawant 76 Reputation points

HI Team,

We have requirement to extract all azure VM's whose OS version is windows server 2012 and 2012 R2 along with their license policy.

please can you provide any PowerShell script or another way or query to extract these details?

please help me to get this details.


Jayesh Sawant

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,293 questions
Windows Server 2012
Windows Server 2012
A Microsoft server operating system that supports enterprise-level management, data storage, applications, and communications.
1,544 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,172 questions
{count} votes

1 answer

Sort by: Most helpful
  1. kobulloc-MSFT 24,321 Reputation points Microsoft Employee

    Hello, @Jayesh Sawant !

    How do I find all of my VM's with an OS version of Windows Server 2012 and 2012 R2 along with their license policy?

    Using Azure CLI, I first got a list of all Windows Server SKUs:

    az vm image list --offer WindowsServer --all --query "[].sku"

    Then I created this (admittedly somewhat clunky) query:

    az vm list --query "[?storageProfile.imageReference.sku=='2012-Datacenter' || storageProfile.imageReference.sku=='2012-datacenter-gensecond' || storageProfile.imageReference.sku=='2012-Datacenter-smalldisk' || storageProfile.imageReference.sku=='2012-datacenter-smalldisk-g2' || storageProfile.imageReference.sku=='2012-Datacenter-zhcn' || storageProfile.imageReference.sku=='2012-datacenter-zhcn-g2' || storageProfile.imageReference.sku=='2012-R2-Datacenter' || storageProfile.imageReference.sku=='2012-r2-datacenter-gensecond' || storageProfile.imageReference.sku=='2012-R2-Datacenter-smalldisk' || storageProfile.imageReference.sku=='2012-r2-datacenter-smalldisk-g2' || storageProfile.imageReference.sku=='2012-R2-Datacenter-zhcn' || storageProfile.imageReference.sku=='2012-r2-datacenter-zhcn-g2'].{VMName:name,Offer:storageProfile.imageReference.offer,SKU:storageProfile.imageReference.sku, LicensePolicy:licenseType}" --output table

    I tested this with a 2012-datacenter-gensecond and some 2019-Datacenter in a slightly modified query and it should give you everything you are looking for:

    enter image description here

    I hope this has been helpful! Your feedback is important so please take a moment to accept answers. If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    User's image

    0 comments No comments