LucD
Leadership
Leadership

You need the VMHost parameter, or a ResourcePool or a vApp.

You don't need the Datastore parameter, if the new VM can be created on the same datastore as the source VM.

If you want to override this behavior and use another datastore, you have to use the Datastore parameter.

You can do a Get-VM on the name VM2, and if it exists remove it.

Something like this

$newVMName = "VM1"
$sourceVMName = "VM2"
$esxName = "MyEsx"

Get-VM -Name $newVMName | Remove-VM -DeletePermanently -Confirm:$false
New-VM -Name $newVMName -VM $sourceVMName -VMHost $esxName


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post