Hybrid Use Benefit: Counting Your VMs

My buddie Jeanne asked me to help her count the number of VMs in her Azure environment that were using the Hybrid Use Benefit (AKA HUB), and I said sure!

HUB allows qualified Microsoft customers to run Windows Server with Software Assurance in Azure saving BIG!
(and no, you can’t use it with AWS – it’s an Azure exclusive!).

The number of VMs you can use with HUB depends on the type and number of Windows Server Licenses you have (that’ll be another blog post) … but you’ll want to be able to keep track, and make sure you use HUB assignments efficiently.

First thing is to see which VMs in Azure you may have already assigned a HUB Benefit.
That’s easy enough with Get-AzureRMVM and a simple select, I pulled the VM name and the “LicenseType” – which shows that for 4 of the 6 VMs, I’ve assigned the HUB benefit to them:


That’s a great first step, but to efficiently use the HUB benefit, I’ll also want to know things like:

  • Windows VMs without the HUB benefit (so I can assign it)
  • # of cores on each VM (since I’ll want to assign it to higher core VMs to maximize my savings)

I know all that info is available to me when I just run Get-AzureRMVM without any options, because I almost see it
(well not the # of cores…but I know they must be there if the VMSize is there!):


That’s not exactly what I need, and I can’t run that one command to get it!

To properly count / assign HUB benefits, I want a simple list with Name, OSType, LisenseType, #of Cores…. BUT, my PowerShell is rusty (happens). I asked someone with way sharper PowerShell than me (Bret – you know who you are!) – here’s what he came up with:

$VMs = Get-AzureRmVM | Select Name,@{Name='VMSize'; Expression={$_.hardwareprofile.VMSize}}, @{Name='OSType'; Expression={$_.StorageProfile.OSDisk.OSType}}, Location, LicenseType
$VMCollection = @()
foreach ($VM in $VMs)
   $VMSize = Get-AzureRmVMSize -location $VM.Location | where { $_.name -eq $VM.VMSize }
   $PropertyHash = [ordered]@{
                               VMName = $VM.Name
                               OSType = $VM.OSType
                               LicenseType = $VM.LicenseType
                               NumberOfCores = $VMSize.NumberOfCores
   $VMObject = New-Object -TypeName PSObject -Property $PropertyHash
   $VMCollection += $VMObject
$VMCollection | ft -AutoSize

The output is EXACLTY what I wanted:


With that information, informed decisions can be made on optimally assigning HUB benefits (another blog post!).