VMware Cloud Community
LookingForConve
Contributor
Contributor

How can I create some VM from existing VM but on the other host by using powerShell toolkit script?

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

0 Kudos
2 Replies
LucD
Leadership
Leadership

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

0 Kudos
ggochkov
VMware Employee
VMware Employee

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

0 Kudos