I need to create a new VM on a destination host ESX01 by using an existing VM but on the other host ESX02.
Can someone show me how I can create a powersell script for this task by using VMWare toolkit for powershell?
Thanks
In the current VITK build there are no "cloning" cmdlets afaik.
You can use the SDK method CloneVM_Task.
From ESX 3.5 u2 onwards you can even use this on "live" guests.
See for a sample script.
In the VirtualMachineCloneSpec object you can use the location property to specify a host.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If the two ESX host are managed by the same VC you can use powershell cmdlets to do this in 2 steps:
Assume $vm1(on host $h1) is the VM to clone, and $h1, $h2 are the ESX hosts and they are added on Datacenter with name "theDCName":
$tpl1 = New-Templte -VM $vm1 -Location (Get-Datacenter -Name theDCName) -Name tpl1
$vm2 = New-VM -Name vm2 -Template $tpl1 -VMHost $h2