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
#1 by Ben on October 8, 2009 - 1:44 am
Quote
Does this method still have the limitation of 8 VMs in a linked virtual machine group, as it does when using the Web Services SDK?
#2 by Keshav Attrey on October 8, 2009 - 4:38 pm
Quote
I believe you’re referring to the VMFS limitation that at any one time no more than 8 different ESX hosts can run VMs sharing the same base disk:
http://kb.vmware.com/kb/1003319
That is still a limitation. If you have a VM on a shared datastore, then you can create 100 linked clones from that VM, causing 101 different VMs to share the same base disk. But you cannot run those VMs on more than 8 different ESX hosts.
#3 by Polprav on October 22, 2009 - 12:09 am
Quote
Hello from Russia!
Can I quote a post in your blog with the link to you?
#4 by Keshav Attrey on October 22, 2009 - 8:24 pm
Quote
Of course!
#5 by Carter Shanklin on December 20, 2009 - 10:14 am
Quote
Here’s the same thing in an advanced function for better pipelining http://poshcode.org/1549
Keshav, blog some more entries, man. Fame and fortune awaits!
#6 by michael on January 11, 2010 - 6:36 am
Quote
thanks! great script
Pingback: Liens du jour #5 - Hypervisor.fr
Pingback: PowerCLI: A Simple VMware Backup Script – Gestalt IT
#7 by Rob Daly on July 21, 2010 - 1:49 pm
Quote
Keshav / Carter – is there any way to specify a snapshot point other than the CurrentSnapshot? Haven’t been able to figure this out. Thanks for your help.
#8 by Keshav Attrey on July 21, 2010 - 2:34 pm
Quote
Can you use vm.snapshot.RootSnapshotList[i] followed by a sequence of ChildSnapshotList[i] to navigate the snapshot tree, followed by “snapshot”?
$vm.snapshot.RootSnapshotList[0].snapshot
$vm.snapshot.RootSnapshotList[0].ChildSnapshotList[1].snapshot
etc.
#9 by Keshav Attrey on July 21, 2010 - 2:39 pm
Quote
Might also be able to use
$snap = (get-snapshot -vm $vmName $snapshotName) | get-view
$snap.moref