Howto Add an existing VHD to a running VM

Nov 3, 2010 at 3:38 PM

Hi,

I want to move an existing VHD from one running VM to another VM using a PS script.
I was able to do this with PassThrough disks using a PS script before, but when I try to use Add-VMDisk I get a message the VM is still running.

This is the script I was using:

. C:\PS_Scripts\hyperv.ps1

$vm = gc env:computername
# vm = Virtual Machine
$st = $args[0]
# st = Start Type
$si = $args[1]
# si = System Instance

if ($st -eq "Prepare")
{
 if ($si -eq "ci")
 {
  add-vmpassthrough $vm 0 15 -scsi "Disk 19" -Server blade9-sap
 } else {
  add-vmpassthrough $vm 0 16 -scsi "Disk 20" -Server blade9-sap
 }
}


if ($st -eq "Unprepare")
{
 if ($si -eq "ci")
 {
  remove-vmdrive $vm 0 15 -scsi -Server blade9-sap
 } else {
  remove-vmdrive $vm 0 16 -scsi -Server blade9-sap
 }
}

Please advise