title: Powershell: copy-item attach .vhdx to VM
body: <p>My goal is to create a new VM, copy a <code>.vhdx</code> to a location, add the <code>.vhdx</code> to the new VM and then boot form it.</p>
  
  <p>My issue is that the <code>.vhdx</code> is not attaching to the VM. I'm not sure why. </p>
  
  <p>I want to say the <code>Copy-Item</code> is wrong since it get hung when I run that line, at least it seems that way as it never completes and I am trying this on an <code>SSD</code> drive. </p>
  
  <pre><code>$VM_NAME = "PS_TEST_VM"
  $VM_RAM = 1GB
  $VM_RAM_MAX = 2GB
  $VM_CPUS = "4"
  $VM_DEST_PATH = "C:\Users\Public\Documents\Hyper-V\Virtual hard disks"
  $VM_TO_COPY = "WIN81.1.vhdx"
  $VM_HOST = "MAINKITTEN"
  $NETWORK_SWITCH = "DEFAULTSWITCH"
  $ROOT_VHD_TPL = "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\WIN81.1.vhdx"
  
  # CREATE
  New-VM -Name $VM_NAME -Path $VM_DEST_PATH -NoVHD -Generation 2 -MemoryStartupBytes $VM_RAM -SwitchName $NETWORK_SWITCH 
  Set-VM -Name $VM_NAME -ProcessorCount $VM_CPUS -DynamicMemory -MemoryMinimumBytes $VM_RAM -MemoryStartupBytes $VM_RAM -MemoryMaximumBytes $VM_RAM_MAX
  # COPY AND ATTACH
  Copy-Item -Path "${VM_DEST_PATH}\${VM_TO_COPY}" -Destination "${VM_DEST_PATH}\${VM_NAME}.vhdx"
  Add-VMHardDiskDrive -VMName $VM_NAME -path "${VM_DEST_PATH}\${VM_NAME}.vhdx"
  
  Start-VM $VM_NAME
  echo "done"
  </code></pre>