How to attach an existing vhd/x in Virtual Machine with HYPER-V

When you create a new virtual machine in HYPER-V you must create and new virtual hard disk (vhd,vhdx).

There are times that you want to attach an existing vhd,vhdx in a new virtual machines or an already created for different reasons.

For example you want to transfer files in new Virtual machine or create a duplicate virtual machines in a test environment.

All these changes and test you can do it in healthy Lab Environment with HYPER-V

So let's start to describe how can do this.

 

Attach VHD/X in already created Virtual Machine 

  • Open Hyper-v Manager
  • Select the Virtual Machine that you would like to attach a virtual disk
  • Click in Settings from the right side.
  • Click in SCSI Controller from the left side
  • Select Hard drive and click Add

  • Click Browse and find the virtual disk that you would like to attach
  • Click OK

  • Login in Virtual Machine
  • For Windows 8.1,Windows 10, Windows 2012 right click in the start and select Disk Management .
  • For Windows Server 2008 R2 click in Server Manager - - > Storage - - >Disk Management
  • The disk that you will have attach will be offline. Right click in the Disk and select Online.

 

Altaro Banner

 

Attach VHD/X while create new Virtual Machine

You can attach an existing vhd/x while create a new virtual machine from HYPER-V GUI or Create and Configure Virtual Machine with PowerShell.

  • Open Hyper-v Manager
  • Select New - - ->Virtual Machine from the right side.
  • Click Next
  • Write the name of the Virtual Machine.
  • Check in Store the virtual machine in different location and select where you want to save. Click Next

  • Select Generation 2 or 1. General today use Generation 2.

  • Type the MB's that you want for the RAM

  • Configure the Network adapter or leave it as it.Click Next

  • Select use an existing Virtual Hard disk.
  • Click Browse and find the vhd,vhdx that you want to use.Click Next

  • This is a summary of all your settings.Just click  Finish

As you can see to attach an existing vhd or vhdx it's very simple with HYPER-V.

 

> Video : Implementing Windows Server 2016 Hyper-V by Greg Shields (MVP)

 

Remove VHD/X from a  Virtual Machine

Let's say that we have a Virtual Machine with multiple Virtual Hard Disks and want to remove one of them.

  • Open Hyper-v Manager
  • Select the Virtual Machine that you would like to remove a virtual disk
  • Click in Settings from the right side.

 

  • Expand the  SCSI Controller from the left side
  • Select the virtual hard disk that you want to remove.
  • Click in button Remove from the right side.
  • The Remove will not delete the virtual hard disk. Only will disconnected  from the Virtual Machine.
  • If you want to delete you must go in the folder that located and deleted

 

Before proceed with the Powershell commands just to note that will be included in Useful Powershell Commands that can use it every day

Attach VHD/X with Powershell

Of course i can't miss how can do it with Powershell. 

In Powershell you can use the command Add-VMHardDiskDrive  with specific Parameters.

So let's type the following command to attach an exisitng vhd/x in specific Virtual Machine

 Add-VMHardDiskDrive -VMName "Windows 10" -Path "F:\HYPER-V\Windows 10 Enterprise\win10.vhdx"-ControllerType SCSI -ControllerNumber 0 -ControllerLocation 1

Now go in the Virtual Machine to see the attach VHD/X that you have done with powershell.

 

Remove VHD/X with Powershell

If you like to use command line you can remove the vhd/x from Powershell.

In Powershell you can use the command Remove-VMHardDiskDrive  with specific Parameters.

But you must be very carefull what you type because you can create a serious problems in your environment. As you can see you must know the number and the location which use and must be 100% sure.

Remove-VMHardDiskDrive -VMName "Windows 10" -ControllerType SCSI -ControllerNumber 0 -ControllerLocation 1

 

Very simple and very useful feature that you can use to configure the Virtual Machine as you want.

What is your thought's?  Do you believe that can help us with more details and knowledge. Write in our commented system to share it with other IT Pro.


 

 

Tags