Monday 10 July 2017

Convert Azure Windows virtual machine license to Hybrid Use Benefit

EDIT: This functionality is now directly in the portal. Just select the VM, click configuration and you should now see the ability to switch license type.

Microsoft has recently announced their hybrid use benefit for Windows virtual machines. They claim a 40% lower price on Windows VMs in Azure which is certainly a good thing.

If you license your on premises hosts with Windows Datacentre and also run some Azure Windows VMs then you can use the license for both - at the same time!

"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. The Azure Hybrid Use Benefit for Standard Edition licences can only be used once either on-premises or in Azure. Datacenter edition benefits allow for simultaneous usage both on-premises and in Azure."

The only issue with this offer is that you need to enable the hybrid use at deploy time on your VMs. This isn't a problem for ephemeral VMs, but if you have permanent VMs that you want to save some money on, then you need to re-provision them.

It is possible to delete your VMs and then recreate them using the original VHD, with the hybrid use benefit enabled. I've written a script which will do just this and published it on GitHub here.

As always, DO NOT use this in production and make sure you have backups of your machines before you use the script!

Be aware that this will only work on some VMs, I've not yet worked out the prerequisites. The script *should* detect if it hasn't worked and put your VM back with it's original license if the ARM platform throws an error. To put this in perspective, I've run the script on 8 VMs, 1 of which didn't work.

Update: Should now work with managed disk VMs


  1. Good day. Great script thanks.

    As far as I can see it works fine on a server with a storage account but unable to run on B-Series VM's and Managed Disk VM's.

    Do you maybe have an updated version on where VM's with managed disks can be converted?


    1. Hi, I've updated the script to work with managed disk VMs.

      I've tested on a B Series VM and it works, if there is still an issue, can you explain it and paste the error please.

      Thanks for your feedback.

  2. This is the only version I have at present, I've not tested on B series or managed disk VMs.

    I haven't looked at how to remove / re-add a VM with a managed disk, but I assume the issue is when re-attaching the disks to the VM since I guess there will be no URI for the disk.

    If I get some time, I'll take another look.

  3. This comment has been removed by a blog administrator.

  4. Hi

    It fails for me with this error, the vm is using managed disks.

    I'm not sure why its complaining about the below storage account ('xxxxxazurexxx' )?
    Any idea why, please let me know?

    Standard DS2 v2 (2 vcpus, 7 GB memory)

    Recreate the VM...
    New-AzureRmVM : Long running operation failed with status 'Failed'.
    ErrorCode: StorageAccountTypeNotSupported
    ErrorMessage: Storage account 'xxxxxazurexxx' is of Standard_ZRS type. Boot Diagnostics supports
    Standard_GRS,Standard_LRS,Standard_RAGRS storage account types.
    StartTime: 06/11/2017 12:26:31
    EndTime: 06/11/2017 12:26:31
    OperationID: ff83ce40-d005-4e61-a3c2-6ee6687f56e7

    1. Sounds like that storage account is in use for VM diagnostics maybe? I'll make a VM with diagnostics enabled and see if I can reproduce

    2. Works fine with a configured boot diagnostics account on a VM for me.

      Looks like your diagnostics storage account is ZRS which is not supported and that's why the VM can't be recreated.

      I'm not sure how you created that VM in the first place? I'm unable to set my boot diagnostics account in the portal to a ZRS storage account. Because of this I can't really fix this issue.

  5. Hey Dave, how would you go about using the XML file to restore a VM if you have issues with the script?

    1. I would actually ignore the xml and create a new VM of the same size and attach the VHD using PowerShell:

      Or the Quickstart Template

  6. Just as a side note. The option to convert on the fly is now in the portal. Select the VM and go into config.


Please be nice! :)

Nutanix CE 2.0 on ESXi AOS Upgrade Hangs

AOS Upgrade on ESXi from 6.5.2 to hangs. Issue I have tried to upgrade my Nutanix CE 2.0 based on ESXi to a newer AOS version for ...