The following PowerShell code uses VMware vSphere’s CloneVM API to create a linked clone from a source VM’s current snapshot point. The clone will be located on the same host, datastore, and folder as the source VM. It requires a snapshot to exist on the source VM, and it requires vCenter Server.

connect-viserver "vCenter_hostname"
$sourceVM = Get-VM "source_vm_name" | Get-View
$cloneName = "linked_clone_name"
$cloneFolder = $sourceVM.parent

$cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
$cloneSpec.Snapshot = $sourceVM.Snapshot.CurrentSnapshot

$cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
$cloneSpec.Location.DiskMoveType = [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking

$sourceVM.CloneVM_Task( $cloneFolder, $cloneName, $cloneSpec )

-Keshav Attrey

Tags: , ,