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:
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!