Azure: Cost Optimisation – Enabling Hybrid Use Benefit (HUB)

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.


The first thing to do is make sure that you have the Azure PowerShell module installed.

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.

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.

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.

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.

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.


For more details checkout the Microsoft document site

Assigning static IP to an Azure VM

As cheap as Microsoft Azure is, keeping cost down is one of the main concerns to any organisation. One of the ways to do this when running IaaS in the cloud, is to power off virtual machines when they are not required.

When stopped, Azure VMs will remain in one of two different states:

Stopped (StayProvisioned)
Stopped (Deallocated)
Stopping a VM from within the guest OS or by using the Stop-AzureVM with the -StayProvisioned switch will power the VM off but leave it in the StayProvisioned state. This will leave any allocated resources attached to that VM,  such as its network adapter.

Stop-AzureVM -ServiceName "myservice1" -Name "MyVM" -StayProvisioned

In this state, IP addresses assigned via DHCP stay assigned to the VM for when its next powered up. Initially this sounds great, but whilst in this state, although the VM is stopped, the resources that remain attached are incurring billing.

However, a virtual machine stopped using the SHUT DOWN button from the Azure Portal


or by using the Stop-AzureVM without the -StayProvisioned switch, powers off the VM and places it into a Deallocated state.

Stop-AzureVM -ServiceName "myservice1" -Name "MyVM"

In this state its resources are not reserved and released back to the Azure fabric. When it comes time to power the VM back up, all recourses are reprovisioned including the network adapter and an new IP address. The benefit of a VM in the Deallocated state is that it will not incur any billing, the downside is that it could have a different IP address the next time it starts up.

So how do we achieve the best of both worlds?

Since the release of PowerShell cmdlets for Windows Azure version 0.7.3 released at February 12, 2014  it is possible to glue a static IP-address to a particular virtual machine. So even if a VM is not running for a while and in the Deallocated state, it will receive it’s originally assigned IP-address at boot.

To test if an IP address is already in use in the subnet

Test-AzureStaticVNetIP -VNetName "TechKB ADFS Virtual Network" -IPAddress


To assign a static IP address

Get-AzureVM -ServiceName CloudServiceName -Name VMName | Set-AzureStaticVNetIP -IPAddress | Update-AzureVM


To remove a statically assigned IP address

Get-AzureVM -ServiceName CloudServiceName -Name VMName | Remove-AzureStaticVNetIP | Update-AzureVM


The following PowerShell code lists all virtual machines, their cloud service, and whether they have an assigned, reserved IP address.

Get-AzureVM | Select-Object -Property Name, ServiceName, @{Name='ReservedIP';Expression={(Get-AzureStaticVNetIP -VM $_ ).IPAddress}} | Format-Table -AutoSize


And that’s all for this post, hope it help!

Connecting Azure PowerShell to your Azure Subscription

** This process has changed, keep a look out of an updated article! **

Azure is becoming an ever more powerful cloud solution, with new services and improvements added almost on a daily basis. Microsoft Azure Management Portal offers the ability to manage many of these services, however the only way for administrators to make use of its full potential is by utilising PowerShell. Currently deploying multi NIC virtual machines is an example where PowerShell can achieve more than the normal portal.

Setting up your environment to enable remote management is achieved with two steps:

  1. Installing the Microsoft Azure PowerShell module on your client machine
  2. Connecting to your Microsoft Azure Subscription

When connecting to Microsoft Azure, administrator have two methods available to them.

  • Azure AD – This is generally the recommended authentication method since it makes it easier to manage access to the subscription.
  • Certificate Method – This is quickest and easiest to setup, good for testing with your own subscription. However its only valid as long as the subscription and certificate are valid for and makes it harder to manage access to a shared subscription.

The following section of this post will step through the installation of the Microsoft Azure PowerShell module and connecting in to an Azure subscription using the certificate method.

Installing the Microsoft Azure PowerShell Module

The first requirement to managing Microsoft Azure with PowerShell is to download and install the Azure PowerShell module. The simplest way to do this is run the Microsoft Web Platform Installer and step through the installation wizard.



Connecting to your subscription

Once the Microsoft Azure PowerShell module has been installed, the next step is to connect it to your Azure subscription. To do this we need to download the subscription information that contains the management certificate needed to connect PowerShell to your subscription. The Microsoft Azure PowerShell module includes cmdlets to allow you to download and import the certificate.

The first step is to open the Microsoft Azure PowerShell command window.


The next step is to use the following cmdlet to download your publishing profile.



This cmdlet opens a webpage on the Microsoft Azure Management Portal and its from here you can select and download your publishing profile. The publishing profile is in the form of a .publishsettings file.



Once you have downloaded your publishing file, the next step is to import the information into PowerShell. To do this run the following command replacing the location of the downloaded file.

Import-AzurePublishSettingsFile C:\Downloads\


Once your publishing information has been imported, you should be connected to your Azure subscription. We can now use PowerShell to check subscription details. The following cmdlet displays the connected subscription ID, subscription name and other subscription details that make it possible to test that we are connected to the correct subscription.



Its as simple at that!

Check out future posts to see how to deploy basic virtual machines in Azure using PowerShell.

Helpful Cmdlets

Over the past few years when deploying Hyper-V, SCVMM or Windows Clustering, I have found myself searching around for little snippets of PowerShell or Cmdlets to make basic configuration changes to the environments. I know there are some fantastic scripts out there that will step you from the beginning to end of full builds, but on many occasions, these short one or two liners have been of great help.

If all goes to plan, I will add additional posts to the series with similar content.

Changing the metrics of a cluster network

(Get-ClusterNetwork “CSV Network”).Metric=900

Revert the network back to autometric

( Get-ClusterNetwork “Cluster Network 1” ).AutoMetric = $true

The network metric is used by windows to determine which network should be sued for CSV communications when cluster shared volumes are installed. The lowest metric network would be chosen for this purpose with the second lowest being designated for live migration. (It is possible to also select a live migration network from within the GUI)

Check ODX Status (return value 0 = ODX enabled, return value 1 = ODX disabled)

Get-ItemProperty hklm:\system\currentcontrolset\control\filesystem -Name “FilterSupportedFeaturesMode”

Disable ODX

Set-ItemProperty hklm:\system\currentcontrolset\control\filesystem -Name “FilterSupportedFeaturesMode” -Value 1

ODX is a feature that allows Windows to move or copy data from one device to another or one location on a device to another location on the same device without transferring the data through the windows device. Essentially offloading the workload to the device and speeding up the transfer.

Disable TRIM

fsutil behavior set disabledeletenotify 1

Re-Enable TRIM

fsutil behavior set disabledeletenotify 0

SCVMM 2012 R2 displays duplicate VMs

Get-VM “DuplicateVM” | Where Cloud -eq $Null | Remove-VM -force

This command will remove the VM from the SCVMM DB, yet leave the VM on the Hyper-V host/Cluster. Once removed from SCVMM, refresh the cluster to reregister the VM in SCVMM.

Discover WWN info from a Hyper-V host using PowerShell

Open up a powershell with administrator privileges, then run: Get-InitiatorPort

Fibre Output:


iSCSI Output:


Disable all disconnected Adapters on a Hyper-V host

Get-NetAdapter -Physical | Where-Object {$_.Status -eq “Disconnected”} | ` Disable-NetAdapter }

How to add host management credentials to Hyper-V Hosts in SCVMM that are greyed out via the console

Open PowerShell and Import the SCVMM Module, or open SCVMM PowerShell from the top ribbon in the SCVMM console.

$YourCluster = Get-SCVMHostCluster -Name YOUR-CLUSTER-NAME

$YourRunAs = Get-SCRunAsAccount -Name “YOURRUNASACCOUNT”

Set-SCVmHostCluster -VMHostCluster $YourCluster -VMHostManagementCredential $YourRunAs

Replace YOURRUNASACCOUNT with VMM Run as account and YOUR-CLUSTER-NAME with name of cluster. It can take a minute to run, but afterwards your hosts in the cluster will be managed with the new Run As account. You can right click on any host and go to properties > Host Access to verify.

Dual boot from VHDX

I have recently purchased a new laptop and been researching the best ways to dual boot in Windows 8.1. I chose to dual boot from a VHDX file so I could either boot directly into my sandbox OS or run it from within Hyper-V should I have booted into my main OS.


The first step to do this was to install my main OS, then once installed open up Hyper-V manager and build myself a VM in the normal way.


The next step is to browse to the location on the hard disk where you have created the VMs hard disk. Once located, right click on the VHDX and select mount to mount the VHDX as a local drive.


Once you have mounted the drive, take note of the drive letter assigned to it.


The next step is to open an admin command window and using the BCDBOOT command run:

bcdboot <drive>:\Windows

Where <drive> is replaced with the letter of the mounted VHDX, in my case:

bcdboot F:\Windows


Once that has completed successfully, eject the mounted drive by right clicking on in and selecting eject. Now you can reboot and should be offered the option to boot to the VHDX OS as well as the main OS.

It is possible to run MSCONFIG and change the default boot and boot time. Its also possible to use BCDEDIT to change the description displayed on the boot window, as well as many other setting.

NOTE: Always make a backup with BCDEDIT before making changes.

To list boot options:


To change the description of a boot option:

bcdedit /set {boot loader identifier} description “Windows 8.1”

To list more information about the command:

bcdedit /? 


Configuring CSV Cache in Server 2012 R2

Microsoft introduced CSV Cache for Hyper-V and Scale-Out File Server Clusters in Windows Server 2012. Essentially CSV Cache allows the administrator to configure a percentage of the hosts RAM  to cache read IOPS in the memory of the Hyper-V or the Scale-Out File Server Cluster nodes. When introduced in Windows Server 2012 the administrator was required to set the CSV Block Cache and enable it on every CSV volume. In Windows Server 2012 R2 CSV Block cache is by default enabled for every CSV volume but the size of the CSV Cache is set to zero, this obviously makes administration much simpler as only the size of the cache needs to be configured.

The following PowerShell can be used to set the Block Cache size.

# Get CSV Block Cache Size
# Set CSV Block Cache Size to 512MB

Microsoft recommendations:

  • Hyper-V Host – 512MB cache
  • Scale-Out File Server Node – Windows Server 2012 allowed a cache size up to 20% of the servers RAM, in Windows Server 2012 R2 Microsoft changed this to be up to 80% of the RAM of a Scale-Out File Server Node.

Deployment Image Servicing and Management: DISM

I have recently been involved with WDS and working on deployment images with DISM and found these articles to be of great help. If you’re planning to get involved in a similar venture these are well worth a read.

Edit BCD to allow dual boot of Windows 8

Using bcdedit.exe /enum

To enable the computer to also boot to a second Windows 8 you can use bcdedit.exe with the following command which will copy the current Windows Boot Loader details for Windows 8 to a second record for Windows 7/8 or Server 2012.

bcdedit.exe /copy {current} /d “Second Microsoft Windows 8″

bcdedit.exe will respond with something like the following.

The entry was successfully copied to {…………………………..}.

Using bcdedit.exe /enum to again enumerate through the current entries within the BCD store you’ll see the newly added entry.

Before you can use the newly created Windows boot loader configuration, you’ll need to change the partition for the second Windows 8 using the following two bcdedit.exe commands.

bcdedit.exe /set {……………………………} device partition=D:

bcdedit.exe /set {……………………………} osdevice partition=D:

If you now reboot the system you should now be able to boot into either copy of Windows 8.