Problem solve Get help with specific problems with your technologies, process and projects.

Use your PowerShell prowess to add VHD files to a Hyper-V VM

Need to import VHD files into Hyper-V, but don't know how to go about it? PowerShell to the rescue!

How do I import VHD files into Hyper-V?

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.

Dig Deeper on Virtual machine provisioning and configuration

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.