PowerShell One-Liner To Convert Multiple VHD to VHDX #HyperV #PowerShell


Since the release of Windows Server 2012 and Windows 8, Microsoft added a new type and default format of virtual hard disk (VHDX). There are a lot of benefits of using VHDX over VHD files on-premises. I mentioned on-premises, because as of today Azure supports only VHD and not VHDX.

You can read about the improvements and why you should consider using VHDX in Hyper-V whenever possible here.

Microsoft also included two options to convert to VHDX. You can you use Hyper-V Manager Edit Disk option.

Or, you can also use PowerShell to do so using Convert-VHD cmdlet.

In this post, I will show you how to convert multiple VHD files to VHDX format in a single PowerShell One-Liner command.

PowerShell One-Liner To Convert Multiple VHD to VHDX

The following code will convert all VHD files in a source path to VHDX format in a destination path, and finally set the Physical Sector Size Bytes to 4096 (4K).
As a side note, when you create a new VHDX file, it has a physical sector size of 4K by default. However, a converted VHDX file has a physical sector size of 512 Bytes. This step is very important, because the data storage industry will be transitioning the physical format of hard disk drives from 512-byte sectors to 4,096-byte sectors (also known as 4K or 4KB sectors). This transition is driven by several factors. These include increases in storage density and reliability.

How to use this tool?

You can run this tool using a single line of PowerShell.

Now you have converted multiple VHD files to the latest virtual machine storage, the VHDX format virtual hard disk.

Where can I download this script?

This script is available on my GitHub repository. You can download it from here. If you have any feedback or changes that everyone should receive, please feel free to update the source and create a pull request.

Hope this helps!


About Charbel Nemnom 399 Articles
Charbel Nemnom is a Cloud Solutions Architect and Microsoft Most Valuable Professional (MVP), totally fan of the latest's IT platform solutions, accomplished hands-on technical professional with over 17 years of broad IT Infrastructure experience serving on and guiding technical teams to optimize performance of mission-critical enterprise systems. Excellent communicator adept at identifying business needs and bridging the gap between functional groups and technology to foster targeted and innovative IT project development. Well respected by peers through demonstrating passion for technology and performance improvement. Extensive practical knowledge of complex systems builds, network design and virtualization.

Be the first to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.