MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.01k stars 21k forks source link

Azure Resource Graph query | get VM license benefit type #53811

Closed sayanghosh123 closed 4 years ago

sayanghosh123 commented 4 years ago

I can get a no of things about VMs from "resources | where type =~ 'Microsoft.Compute/virtualMachines'" and then expanding the properties. What I am looking for is the Windows license type. The same information is available on the portal under "Virtual Machines" - add Columns - "OS licensing benefit". The values are of type "Azure hybrid benefit", "Not enabled" etc.

I can get the same information for SQL Server on IaaS via properties.sqlServerLicenseType in microsoft.sqlvirtualmachine/sqlvirtualmachines, so guessing there is a way to get it for VMs? Any feedback will be greatly appreciated.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

KrishnaG-MSFT commented 4 years ago

@sayanghosh123 AFAIK below is the query you can use to fetch license type information.

resources | where type =~ 'Microsoft.Compute/virtualMachines'| extend licenseType = tostring(properties.['licenseType'])

If you opt ' Yes' as shown below then 'licenseType' property is provided in 'properties' column of the query's output.

image

Typical values for 'licenseType' property are ''Windows_Server" (for Windows server images like 2019 DC, etc.) and "Windows_Client" (for Windows client images like Win 10, etc.)

KrishnaG-MSFT commented 4 years ago

@sayanghosh123 Closing this issue for now. If there are further questions or feedback regarding referred Azure document then please let us know so that we will gladly continue the discussion.

sayanghosh123 commented 4 years ago

Thanks @KrishnaG-MSFT - you are awesome! That seems to work. Just one final clarification -

This seems to show "Windows_Server" where AHB is used, and blank elsewhere. Portal shows

KrishnaG-MSFT commented 4 years ago

@sayanghosh123 Sure. Please find my response below.

Yes, query will show blank under 'licenseType' column

Yes, query will show blank under 'licenseType' column

Yes, query will show "Windows_Server" under 'licenseType' column

sayanghosh123 commented 4 years ago

Thanks @KrishnaG-MSFT - you are awesome!

TiloGit commented 1 week ago

here a version to only get Windows VM and summarize the result:

Resources
| where type =~ 'Microsoft.Compute/virtualMachines' and properties.storageProfile.osDisk.osType =~ 'Windows'
| summarize count() by tostring(properties.['licenseType'])