I used to spend most of my time discussing with customers the benefits of moving business services to the cloud. Most no longer need to be convinced, in fact many have already dabbled with services and instead are looking for guidance on how to enforce governance and better manage costs.
Cost optimisation in Azure is a large topic and by adopting a number of technologies and processes it is possible to make rewarding cost savings.
Along with investing in reserved instances one of the biggest cost savers for Windows VMs can be make through the use of the Microsoft Hybrid Use Benefit (HUB).
What is Hybrid Use Benefit (HUB)
The Azure Hybrid Benefit helps you get more value from your Windows Server licences and save up to 40 per cent* on virtual machines. You can use the benefit with Windows Server Data Centre and Standard edition licences covered with Software Assurance or Windows Server Subscriptions. Depending on the edition, you can convert or re-use your licences to run Windows Server virtual machines in Azure and pay a lower base compute rate (Linux virtual machine rates).
* Actual savings may vary based on region, instance type or usage.
Paragraph from HUB FAQ
It’s worth noting that licensing entitlement is different between Windows Server Datacentre and Windows Server Standard editions.
- Windows Server Datacentre with Software Assurance allows you to use the license on-premises and simultaneously in Azure
- Windows Server Standard with Software Assurance allows you to use the license on-premises or in Azure
With both editions, each two-processor licence or each set of 16-core licences are entitled to two instances of up to 8 cores, or one instance of up to 16 cores.
Enabling Hybrid Use Benefit
Hybrid Use Benefit can be enabled when deploying a Windows VM either from the marketplace, as part of an ARM template or PowerShell script. It can also be enabled post deployment.
I’ve focused on PowerShell and outlined below are a few commands that might be of use. Its also worth mentioning that its possible to do the majority of this through the portal or Azure CLI.
Dependencies
The first thing to do is make sure that you have the Azure PowerShell module installed.
1 |
Install-Module AzureRM |
If you already have the module installed, I would suggest checking that you are running the latest version. This can be done by running the following command.
1 |
Update-Module -Name AzureRM |
How do I know if Hybrid Use Benefit is enabled on a VM?
Its possible to check if Hybrid Use Benefit is enabled on a machine by looking at the virtual machines blade in the Azure Portal.
Browse to the virtual machine blade, from the top ribbon select Edit columns and then add Azure Hybrid Benefit to the selected columns list.
Once the Hybrid Use Benefit column has been added to the blade view, its easy to scan down and see which machines have been enabled or not.
As you would expect, its also straight forward to pull back the same information across all machines using a simple PowerShell command.
The following PowerShell snippet outputs just the Windows machines that HUB is enabled for and ignores the rest.
1 2 3 |
$vms = Get-AzureRMVM $vms | ?{$_.LicenseType -like "Windows_Server"} ` | select ResourceGroupName, Name, LicenseType |
This screenshot is of the above PowerShell snippet being run from within Azure Cloud Shell.
Converting an already deployed VM
For Windows machines deployed with Pay-as-you-go licensing, its a simple process to convert them to Hybrid Use Benefit. As before this can either be done from within the Azure portal or using a simple PowerShell command such as the one below.
1 2 3 |
$vm = Get-AzureRmVM -ResourceGroup "rg-name" -Name "vm-name" $vm.LicenseType = "Windows_Server" Update-AzureRmVM -ResourceGroupName rg-name -VM $vm |
NOTE: Changing the license type only updates the machines metadata flag. This means there is no downtime or service interruption to the system.
Converting back to Pay-as-you-go Licensing
Reverting the VM to Pay-as-you-go licensing is done using the same command. This time, the licensing type needs to be changed to None before running.
1 2 3 |
$vm = Get-AzureRmVM -ResourceGroup "rg-name" -Name "vm-name" $vm.LicenseType = "None" Update-AzureRmVM -ResourceGroupName rg-name -VM $vm |
Change the license type of every Windows VM in the subscription
Updating the license type of multiple VMs one at a time can be very time consuming. To speed things up, I would recommend reviewing the following script created by Neil Bird a Premier Field Engineer at Microsoft.
The script not only allows you to change the licensing type across all Windows VMs but it also offers a Simulate Mode where no changes are actually made. Instead, LOG and CSV export files are generated to show what changes the script would make if ran in Update Mode.
https://gallery.technet.microsoft.com/Azure-Enable-Hybrid-Use-1977e089
For more details checkout the Microsoft document site https://azure.microsoft.com/en-gb/pricing/hybrid-benefit/