How do I import VHD files into Hyper-V?
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
Whether you want to add VHD files to a new virtual machine or import one from an exported VM, you can accomplish the tasks quickly and easily with PowerShell and the Hyper-V cmdlets.
If you have properly exported your VM using the graphical Hyper-V manager or PowerShell, retaining all memory and network settings, you will just as easily be able to import the VM back into Hyper-V.
The following shows an example of exporting a VM to disk, removing the VM from Hyper-V and importing the VM back into Hyper-V.
PS > Export-VM –Name Server1 –Path d:\
PS > Remove-VM –Name Server1
PS > Import-VM –Path ‘c:\Server1\Virtual Machines\BB75F3E6-44E0-4688-86
More resources on VHD files
Navigating VHD formats
Backing up VHD files for extra security
How to convert deployment images to VHD files
The –path parameter for the Import-VM cmdlet should be the .XML file under the Virtual Machines folder. This quickly imports the VM, which is ready to be started using the Start-VM command.
I often run into a situation where I have the .VHD (or .VHDX) file and I want to make a new VM in Hyper-V using this .VHD. This situation differs from importing a VM because you need to specify the network switch, as well as memory and processor settings.
The example below shows a VHD named Server1.vhdx. I create the new VM, add it to my existing switch named Inside and then set the memory settings.
PS > New-VM -Name Server1 -VHDPath C:\hyperv\Server1.vhdx -SwitchName (Get-VMSwitch -name inside* | Select-Object -ExpandProperty name)
PS > Set-VMMemory -VMName Server1 -DynamicMemoryEnabled $True -StartupBytes 1GB -MinimumBytes 512mb -MaximumBytes 2GB
PS > Start-VM -Name Server1
Using PowerShell to add or import VMs into Hyper-V allows you to tackle many management problems. You could even take this process a step further and automate the process of migrating several VMs from one host to another.
Related Q&A from Jason Helmick
Find out how easy it is to make the transition from VMware to Hyper-V with SCVMM or the Microsoft Virtual Machine Converter.continue reading
Managing multiple systems from a remote location can help save admins time and money, but first, you need to enable PowerShell remoting.continue reading
Unsure about the way Hyper-V Dynamic Memory works? Find out how it can make your environment more efficient and flexible.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.