Azure Cost Optimisation Series – Enable Hybrid Use Benefit (HUB) Using PowerShell


Hello all,

 

My name is Neil Bird, I am a Premier Field Engineer (PFE) in the UK Cloud & Infrastructure team. I am passionate about helping customers get the most out of Microsoft Azure and Windows Server technologies. This is the second blog post in a series where I will be sharing some information, scripts and approaches to help with Azure Cost Optimisation for IaaS.

 
This week I want to highlight the massive savings customers can benefit from if they have purchased "Windows Server Datacentre with Software Assurance" licences for their on-premises workloads. Software Assurance (SA) licencing enables customers to deploy new (or upgrade existing) Windows Server instances using latest version of Windows Server. However, in addition to always being able to use the latest version of Windows Server Operating System, Software Assurance enables customers to make savings on Virtual Machine running costs in Azure. This makes Software Assurance even more compelling, as the savings can soon add up to huge amounts depending on the number of VM instances you have deployed in Azure.

 
Extract from: Azure Hybrid Benefit for Windows Server

 

    For customers with Software Assurance, Azure Hybrid Benefit for Windows Server allows you to use your on-premises Windows Server licenses and run Windows virtual machines on Azure at a reduced cost. You can use Azure Hybrid Benefit for Windows Server to deploy new virtual machines from any Azure supported platform Windows Server image or Windows custom images.

 

Azure Hybrid Use Benefit Eligibility:
If you would like to know if you / your organisation is eligible to enable Hybrid Use Benefit in Azure, you need to determine if you have purchased "Windows Server Datacenter with Software Assurance" licences for your on-premises environment and if so, the number of licences you hold. To find this out, you could ask your internal Software Asset Management team (if applicable) who could look in your organisation's Microsoft Volume Licence Service Centre (VLSC) portal. Alternatively, you could ask your Microsoft Software Reseller / Partner, or if you are a Microsoft Premier customer you could ask your Microsoft Technical Account Manager (TAM), who would be able to provide assistance.

 
Windows Server Datacenter vs Standard Licences:
"Windows Server Datacenter with Software Assurance" allows customers to use the licence on-premises AND in Azure (at the same time).
"Windows Server Standard with Software Assurance" allows customers to use the licence on-premises OR in Azure (Not at the same time).

 
Number of Windows Server Datacenter with SA Licences Held:
For each "Windows Server Datacenter with Software Assurance" licence held (16 cores or a 2-Processor Licence), you are eligible to deploy "Up to two VMs and up to 16 cores" with Hybrid Use Benefit (HUB) Enabled. For example: You can enable HUB on "two VMs with 8 vCPUs each, or one VM with 16 vCPUs" per "Windows Server Datacenter with Software Assurance" (16 cores or a 2-Processor) licence your organisation has purchased.

Or to put it another way: For each "16 Core or 2 Proc Windows Server Datacenter with Software Assurance Licence" you have already purchased for On-Premises, you can Enable Hybrid Use Benefit (HUB) on either "2 x 8 vCPU VMs" or "1 x 16 vCPU VM" in Azure.

 
I would like to point out that I am not a licensing specialist, if you have questions on the above or would like to understand more about Azure Hybrid Use Benefit there are a few official Microsoft articles that fully explain the Benefits, Rules and Use Cases for Azure Hybrid Use Benefit (AHUB). There is also a Pricing Calculator tool available. Links to these articles are below:
 

  1. Getting Started with Azure Hybrid Use Benefit for Windows Server
  2. Azure Hybrid Benefit for Windows Server
  3. Azure Hybrid Benefit for Windows Server licensing page
  4. Microsoft Mechanics YouTube Video: How to deploy Azure VMs for less using the Azure Hybrid Benefit for Windows Server
  5. Retirement: Azure Hybrid Use Benefit images for EA subscriptions
  6. Azure Hybrid Benefit for Windows Server FAQ

 
Note - This information is correct at the time this blog post was published. I would always recommend and advise that customers review the latest official Microsoft documentation for any updated terms with regards to Azure HUB.

 
How do I Enable Hybrid Use Benefit on VMs in Azure?
You may have been using Azure to deploy Windows VMs without realising your organisation is eligible to enable Azure Hybrid Use Benefit, this was the case for two customers I have been working with recently. After we determined the number of Windows Server Datacenter with Software Assurance licences they held, they both wanted to "Enable HUB on All Windows VMs in All of their Subscriptions" so that they could instantly start saving on the running cost of their IaaS VMs.

 
To help my customers enable Hybrid Use Benefit on all of their existing Windows VM, in all of their subscriptions in Azure, I wrote a PowerShell script to automate the task and to provide additional audit / reporting information. The script had the following requirements / capabilities:

 

  1. Include a "Simulate Mode" Option
    (This enabled them to audit their subscription(s) and understand what the script "would do" if they run it in update mode)

  2. Export information to a CSV File.
    (This includes VM Name, Resource Group, Size, HUB Enabled (Yes / No), Script Action and Subscription Name and ID)

  3. Provide a "Totals Count" showing the number VMs that have had HUB Enabled
    (This is useful for reporting on success / failure or VMs that are not compatible with HUB such as Linux VMs)

  4. Pass a "Subscription Name", if you do not want to process all subscriptions.
    (Useful if you have a large number of subscriptions.)

  5. Include a "Yes / No" confirmation prompt prior to enabling HUB on a per subscription basis
    (Useful if you want to update the majority of your subscriptions, but not all of them.)

 

I wanted to share my PowerShell script with you, so that other customers can benefit from being able to Enable Hybrid Use Benefit on all existing Windows VMs in all of your Azure subscriptions, using a single PowerShell script.

 
Example screenshot of the script in action:

 
Example screenshot of the script results:

 
Dependencies:
The script requires: "AzureRM" Module v3.2 or above.

    Install-Module AzureRM

 
Or if you already have the "AzureRM" Module installed, check it is running the latest version:

    Update-Module -Name AzureRM

 

Example Syntax to Execute the Script:
Simulate Mode:

    .\azure-enable-hybrid-use-on-all-vms.ps1

Update Mode: (The script displays a yes/no prompt per subscription prior to Enabling HUB on Windows VMs in that subscription)

    .\azure-enable-hybrid-use-on-all-vms.ps1 -SimulateMode $False

 

Output from the Script:
The script generates a CSV file called 'azure-enable-hybrid-use-audit-report.csv' which provides details of the VMs and either the "Action the Script Would Perform" (Simulate Mode), or the "Action the Script has Taken" (Simulate Mode Disabled).
 

Download Link:

Download the PowerShell Script from the TechNet Gallery

 

Feedback: Please let me know if this PowerShell script is useful by posting a comment below.

 

What about Enabling Hybrid Use Benefit for New VM Deployments?
The PowerShell script I have shared with you is designed to Enable HUB on Existing Windows VMs, that is, VMs that have already been deployed into an Azure subscription. For new VM deployments it is possible to enable HUB using ARM JSON or PowerShell so that newly deployed VMs have HUB enabled from their initial creation date.
 

Deploy a New VM with HUB Enabled using ARM JSON Parameter:
Within your Resource Manager templates, an additional parameter licenseType must be specified. Edit your Resource Manager template to include the "license type" as part of the compute provider and deploy your template as normal. Example below:

"properties": {
"licenseType": "Windows_Server",
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
}

 
Deploy a New VM using PowerShell:
When deploying a VM in Azure using PowerShell, there is an additional parameter -LicenseType that can be specified. Example below using the final New-AzureRmVM cmd-let to set the licensing type:

Build VM Configuration as normal using New-AzureRmVMConfig:

$VM = New-AzureRmVMConfig.....

New-AzureRmVM -ResourceGroupName "myResourceGroup" -Location "West US" -VM $VM -LicenseType "Windows_Server"

 

I hope you can use this PowerShell script to help Optimise the Cost of your Azure IaaS Deployments by enabling Hybrid Use Benefit on all existing Windows VMs deployed in your subscription(s).
 

View other blog posts in the Azure IaaS - Cost Optimisation Series

http://aka.ms/AzureIaaSCostOptimisation

 
Cheers
Neil

Comments (0)

Skip to main content