Useful Tools for Hyper-V Administrators
Microsoft recently updated two tools that are useful for IT pros who are deploying Hyper-V: Convert-WindowsImage and Disk2vhd. These updates include support for Windows Server 2012 R2 and Windows 8.1.
Tools for Hyper-V Admins
The Convert-WindowsImage.PS1 script is a free download from the TechNet Script Center gallery. Convert-WindowsImage has been around since the preview releases of Windows 8 and Windows Server 2012, replacing WIM2VHD. You can use this tool to create a virtual hard disk (VHD or VHDX formats) for a virtual machine from the installation media (ISO file) of Windows. For example, say you have downloaded Windows Server 2012 R2 and you’d like to quickly deploy a generalized (Sysprep) virtual machine as quickly as possible. Fire up Convert-WindowsImage, create a new VHDX, and attach it to a virtual machine. Boot up the virtual machine, answer the mini-setup wizard questions, and you have your WS2012 machine up and running.
Convert-WindowsImage is easy to use. You can run the tool completely from the PowerShell prompt (enable the execution of scripts first with either Set-ExecutionPolicy or Active Directory Group Policy); all the instructions can be found on the download page. That option might be useful for regular VM builds from the original Microsoft media (should be rare for most of us because we should use VM templates). Alternatively you can run the tool with the –ShowUI flag to open up a graphical interface and supply all the information there. This approach is much easier, and probably useful for those of us who only create a new virtual machine template whenever Microsoft releases new Windows media.
Creating a VHDX directly from Windows media.
Using Convert-WindowsImage as above will install Windows Server 2012 R2 Datacenter into a new VHDX file. The Windows installation will be generalized as if you had run Sysprep. Note that you could create a VHD file (not that you should, unless you plan to upload the virtual machine to Azure or migrate it to a legacy version of Hyper-V), include an unattended answer file to automatically deal with the mini-setup wizard questions (and more), name the resulting VHDX file, and configure the working directory. You should also be aware that the tool can use a WIM file (such as install.wim as found in the Windows installation media) and that it can query for the possible images within your ISO or WIM file (I chose the full installation of the Datacenter edition).
Version 6.3 of Convert-WindowsImage adds support for creating GPT disks that are used by UEFI based machines. And that allows you to create a virtual hard disk that can be used by Generation 2 virtual machines.
I really like this tool. It might not be supported by Microsoft, but it gives me the quickest way to deploy a new VHD/X file that I can use for:
- Bare metal host deployment: The resulting file can be used by System Center Virtual Machine Manager to deploy Hyper-V hosts to bare metal servers.
- Virtual machine templates: A new virtual machine can be quickly deployed, manually updated, and recaptured as a template.
Another free tool, released under the Sysinternals banner (of Mark Russinovich fame), Disk2vhd gives you a free solution for converting physical disks into virtual hard disks. This is pretty important because – for some reason – Microsoft chose to remove the P2V (physical to virtual) conversion functionality from System Center Virtual Machine Manager 2012 R2. That leaves us with just Disk2VHD as the only Microsoft-provided option.
Disk2VHD is easy to use. Download and extract the zip file before running the executable file on the physical server that you want to capture. By default it will create a VHDX file (new in this version). Application consistency is maintained by creating the virtual hard disk from a Volume Shadow Copy Service (VSS) snapshot. Note that any changes to the capture physical disk(s) after this snapshot will be lost, so shut down any services on the physical machine first.
Check which disks you want to capture and run the tool. You will have a new virtual hard disk that you can attach to a virtual machine when the job is finished. Your original physical server is left untouched so make sure you run either the physical machine or the virtual machine, but not both on the same network at the same time.
Running Disk2vhd to convert a physical disk to a VHDX
Neither of these free tools is supported by Microsoft. However, the creators of these tools have tested them pretty well, and at this time the tools support the latest editions of Windows and Hyper-V.
More in Hyper-V
How to Install Hyper-V on Windows Server Core
Mar 16, 2022 | Michael Reinders
Microsoft Says There Will Be No Hyper-V Server 2022 Free Edition
Dec 13, 2021 | Michael Reinders
How to Stop an Unresponsive Hyper-V Virtual Machine
Jun 29, 2021 | Russell Smith
How to Enable Nested Virtualization in Hyper-V
Jun 28, 2021 | Russell Smith
Disaster Recovery with Azure Backup for SQL Server VMs
May 28, 2019 | Michael Otey
Leveraging Virtualization for Improved Availability and Disaster Recovery
Apr 29, 2019 | Michael Otey
Most popular on petri