Welcome to this guide on enabling Azure Hybrid Benefit.
I have written this down as an easy reference to getting started, covering all the basics from what exactly this benefit is, to finding and enabling it on machines in Azure.
Azure Hybrid Benefit
We will start by talking about exactly what Hybrid Benefit is.
Azure Hybrid Benefit is a cost-savings benefit that lets you bring your existing on-premises Windows Server and SQL Server licences with active Software Assurance or subscriptions to Azure. Save up to 85 percent* compared to standard pay-as-you-go rates and achieve the lowest cost of ownership when you combine Azure Hybrid Benefit, reservations savings and extended security updates. Azure Hybrid Benefit also applies to SQL on Azure and Azure Dedicated Host. Additionally, it provides 180 days of dual-use rights so you can maintain your on-premises operation while migrating to Azure. And now, this benefit applies to RedHat and SUSE Linux subscriptions, too.
FAQ: https://azure.microsoft.com/en-gb/pricing/hybrid-benefit/faq/
You should probably note at this stage Hybrid Benefit is only really worthwhile if you have Software Assurance.
It’s also available directly via Azure itself however.
Software Assurance?
Software Assurance includes an extensive set of technologies, services, rights, and benefits to help you and your organization get the most out of your investments in IT.
So this benefit is in place to assist large organizations minimize costs where possible and probably wont pay as large dividends for small organisations who are more likely to use a PAYG model.
You can find more info here https://www.microsoft.com/en-us/licensing/licensing-programs/software-assurance-by-benefits
Cost Estimates
The below is based on 1000 DS2v2 Windows AVMs (2cores,7GB,14GBSSD,$0.25hr) which are running 730hrs a month.
Monthly Estimates | Enabled | Disabled |
---|---|---|
Azure Hybrid Benefit per month | $53,381.25 | $91,980 |
Savings across eligible Virtual Machines | $38,598.75 | N/A |
The above was obtained using the following https://azure.microsoft.com/en-us/pricing/hybrid-benefit/#calculator
Which machines to enable this benefit on?
Before we enable Azure Hybrid Benefit, we first need to establish why were doing this and what machines we need to target, for example if a machine is constantly online and in use, then it makes perfect sense to enable this for Hybrid Benefit and reduce up-to 49% of our costs. However, if its a device that’s going to be blown away, in a test/dev subscription or is often just left de-allocated / switched off, then its likely we won’t see much savings from enabling it on those machines. In addition, we only have a finite amount of licences and thus we don’t want to enable it for everything (you probably want to have it enabled for some of your ARM templates however, using LicenceType = Windows_Server).
Scope out machines without Hybrid Benefit enabled using a PowerShell command
The below will scan all VMs in your current TenantId / SubscriptionID and print out which are lacking HUB.
Get-AzVM | Where-Object {$_.OSProfile.WindowsConfiguration -and !($_.LicenseType)}
#Credit: https://www.isjw.uk/post/azure/check-azure-hybrid-benefits-with-powershell/
If the results arent what you expect, then double check your TenantId / SubscriptionID using my previous guide.
Enable Hybrid Benefits using a PowerShell script
Once you’ve ensured its the right place to target. The following script can be run from ISE/POSH/VS.
The script will scan all VMs in your current TenantId / SubscriptionID and cycle through each in a loop, printing out the name of the VM it’s enabling on. You can remove | Out-Null from the Update step and this will also give you confirmation each step was successful.
$nonehbvm = Get-AzVM -Status | where{$_.StorageProfile.OsDisk.OsType -eq "Windows" -and (!($_.LicenseType))} | Select-Object Name,ResourceGroupName,Licensetype
foreach($i in $nonehbvm)
{
$vm = Get-AzVM -ResourceGroup $($i.ResourceGroupName) -Name $($i.Name)
"Enabling Azure Hybrid Benefit on $($i.Name) "
$vm.LicenseType = "Windows_Server"
Update-AzVM -ResourceGroupName $($i.ResourceGroupName) -VM $vm | Out-Null
}
#Link: https://jimmyk.azurewebsites.net/2020/03/21/enable-hybrid-benefit-on-all-already-deployed-windows-vms-in-your-subscription/
You will get an output similar to the below:
Enabling Azure Hybrid Benefit on XXXX Enabling Azure Hybrid Benefit on XXXX Enabling Azure Hybrid Benefit on XXXX
Once you’ve run the script, run the below again just to ensure nothings left (assuming all the above was needed).
Get-AzVM | Where-Object {$_.OSProfile.WindowsConfiguration -and !($_.LicenseType)}
#Link: https://www.isjw.uk/post/azure/check-azure-hybrid-benefits-with-powershell/
Alternatively, if you don’t want to use a script then follow for a manual process.
# Manually ADD
$vm = Get-AzVM -ResourceGroup "rg-name" -Name "vm-name"
$vm.LicenseType = "Windows_Server"
Update-AzVM -ResourceGroupName rg-name -VM $vm
# Manually REMOVE
$vm = Get-AzVM -ResourceGroup "rg-name" -Name "vm-name"
$vm.LicenseType = "None"
Update-AzVM -ResourceGroupName rg-name -VM $vm
# A CLI one-liner to enable
az vm update --resource-group myResourceGroup --name myVM --set licenseType=Windows_Server
# A CLI one-liner to disable
az vm update --resource-group myResourceGroup --name myVM --set licenseType=None
#Link: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/hybrid-use-benefit-licensing
Your machines should now be enabled for Hybrid Benefit. You may wish to test to ensure this is true.
How to check in PowerShell
Run the below command to output the LicenceType status of specific machines.
Get-AzVM -Name fisontech-dc -ResourceGroupName fisontech-rg | Select-Object Name,LicenseType
PowerShell
You can also run the following to output the list of all machines in a resource group and their status.
Get-AzVM -ResourceGroupName fisontech-rg | Select-Object Name,LicenseType
How to check in Azure Portal
If you check in the portal, under Virtual Machines blade > Machines-Name > Configuration you should see now see if its enabled or not, for example in my own test environment, I have a Domain Controller configured as below.
Disabled
Enabled
You’re now saving money!
At this point, you’ve done everything you need to start saving money in your environment.
Well done!
If you need more information on Azure PowerShell, use the below link.
Thanks for reading and I hope this guide helps you, please give me a shout if anything needs updating.