Associate the Existing vhd files into script.

Apr 30, 2009 at 8:30 AM

How can I associate the Existing Vhd file into powershell script, Do you have any Idea?

May 5, 2009 at 10:37 AM
 Are you saying you want to build a new VM based on an existing VHD using the script ? Put the following in a .PS1 file and run it with the name, path, memory size, Cpu Count,  Path to an ISO (if any), Network Switch name (remove the -legacy at the end to get a VM bus network).

Param ($vmName=$(throw ("You Must enter a VM name")),
      $vhdPath=$(throw ("You Must enter a VHD Path")),
       $Server="." )
 "Creating VM $VMName"
 $myVM = (New-VM $vmName -Server $server)
 set-vmMemory   $myVM $Memory
 set-VMCPUCount $myVM $cpuCount
 add-vmdrive $myVM 0 0
 add-vmdrive $myVM 0 1 -dvd
 if ($IsoName -ne $null) { add-vmdisk  $myVM 0 1 $isoName -dvd}
 add-vmdisk  $myVM 0 0 $vhdpath
 Add-VMNIC      $myVM $switch -legacy