Answer

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

How do I import VHD files into Hyper-V?

    Requires Free Membership to View

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

67-68C849F47D14.XML'

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.

This was first published in April 2013

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: