How many license do you need?
FinOps first step: create an assessment. Easy to say but if your organization has hundreds of subscriptions, you can’t do it manually. That’s why I wrote a KQL query that calculates how many CPUs you need to cover, including hybrid benefit licenses.
1
2
3
4
5
6
7
8
9
10
11
12
13
Resources
| where type == "microsoft.compute/virtualmachines"
| extend Size = tostring(properties.hardwareProfile.vmSize)
| extend Cores = toint(extract(".+[A-Z]([0-9]+).+", 1, Size))
| extend OsType = tostring(properties.storageProfile.osDisk.osType)
| extend LicenseType = case(isnull(properties.licenseType) or properties.licenseType == "",
"no hybrid benefits",
tostring(properties.licenseType))
| extend Publisher = case(isnull(properties.storageProfile.imageReference.publisher) or properties.storageProfile.imageReference.publisher == "",
"custom image",
tostring(properties.storageProfile.imageReference.publisher))
| summarize TotalCores = sum(Cores) by OsType, LicenseType, Publisher
| order by TotalCores desc
With a small modification, you can also count the number of Windows VMs that are not using a hybrid benefit license.
1
2
3
4
5
6
7
8
9
10
11
12
13
Resources
| where type == "microsoft.compute/virtualmachines"
| extend Size = tostring(properties.hardwareProfile.vmSize)
| extend Cores = toint(extract(".+[A-Z]([0-9]+).+", 1, Size))
| extend OsType = tostring(properties.storageProfile.osDisk.osType)
| extend LicenseType = case(isnull(properties.licenseType) or properties.licenseType == "",
"no hybrid benefits",
tostring(properties.licenseType))
| extend Publisher = case(isnull(properties.storageProfile.imageReference.publisher) or properties.storageProfile.imageReference.publisher == "",
"custom image",
tostring(properties.storageProfile.imageReference.publisher))
| summarize TotalCores = sum(Cores) by OsType, LicenseType, Publisher
| where OsType == "Windows" and LicenseType == "no hybrid benefits"
and so on, if you need the vm list, than just remove the summarize line
1
2
3
4
5
6
7
8
9
10
11
12
Resources
| where type == "microsoft.compute/virtualmachines"
| extend Size = tostring(properties.hardwareProfile.vmSize)
| extend Cores = toint(extract(".+[A-Z]([0-9]+).+", 1, Size))
| extend OsType = tostring(properties.storageProfile.osDisk.osType)
| extend LicenseType = case(isnull(properties.licenseType) or properties.licenseType == "",
"no hybrid benefits",
tostring(properties.licenseType))
| extend Publisher = case(isnull(properties.storageProfile.imageReference.publisher) or properties.storageProfile.imageReference.publisher == "",
"custom image",
tostring(properties.storageProfile.imageReference.publisher))
| where OsType == "Windows" and LicenseType == "no hybrid benefits"
So have fun, but use it at your own risk, and please let me know if you have any questions or suggestions.
This post is licensed under CC BY 4.0 by the author.