The other morning I was reviewing my hyper-v estate for VM’s running with VHD’s in the legacy VHD format. I thought to myself that a script to convert all of the VHD’s but also taking in several other important steps such as shutting down the VM, optimising the new VHDX, shrink the VHD (where possible), connecting the new VHDX and starting the machine would be nice.

I started down the path of writing the script when I came across a post on Aidan Finn’s blog (http://www.aidanfinn.com/?p=16007) which undertook the majority of what I was trying to achieve with the exception that the script runs on a single host. I decided to press on write my own script to cover off the cluster element.

The result is the below script, which only requires the name of your cluster. Once this is specified the script will connect to each of your cluster hosts in sequence, get a list of VM’s with VHD’s and proceed with the conversion process.

There is a section within the script which you can uncomment (AT YOUR OWN RISK) to remove the legacy VHD disks post conversion. As always make sure you have backup’s, allow for downtime and also make sure you have sufficient space on your LUN’s to facilitate the conversion process.  The scripts are provided as is and without support.

Cluster Script :

Cluster Script (With minimal screen feedback):

Single Host Script:



  • Jeffery Hicks (@JeffHicks)
    Posted at 1:32 pm 7th November 2014
    Jeffery Hicks (@JeffHicks)

    Nice. If I may make some suggestions, use a Foreground color with Write-Host so it is clear what are messages and what is output. Even better would be to use Write-Progress. You could also use cmdlet binding and support shouldProcess which would let you use -WhatIf with your script.

    • modalyit
      Posted at 1:37 pm 7th November 2014

      Thanks for the feedback Jeffery, much appreciated. I did originally include foreground colour outputs on the various stages but I removed them in an attempt to be as clean as possible but I take your point. I’ll throw up a modified version later which provides better feedback to the user.

  • Alan Doran
    Posted at 2:40 pm 7th November 2014
    Alan Doran

    Reblogged this on Alan Doran IT Ramblings.

  • Leave a Reply