New-LinkedClone (modification of post by view diff)
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1549"></script>download | new post
PowerCLI script to create linked clones on an ESX server (does require vCenter). This feature is not normally supported on ESX, so this is a pretty nifty thing to do if you like living dangerously. Info on linked clones: http://www.vmware.com/support/ws55/doc/ws_clone_overview.html#wp1028798.
- #Requires -version 2
- # TITLE: New-LinkedClone.ps1
- # AUTHOR: Hal Rottenberg
- # Adapted from a technique published originally by Keshav Attrey http://www.vmdev.info/?p=40
- # Also see William Lam's Perl script: http://engineering.ucsb.edu/~duonglt/vmware/vGhettoLinkedClone.html
- # And Leo's manual version for ESX 3.5: http://blog.core-it.com.au/?p=333
- param (
- [parameter(Mandatory=$true)][string]$SourceName,
- [parameter(Mandatory=$true)][string]$CloneName
- )
- $vm = Get-VM $SourceName
- # Create new snapshot for clone
- $cloneSnap = $vm | New-Snapshot -Name "Clone Snapshot"
- # Get managed object view
- $vmView = $vm | Get-View
- # Get folder managed object reference
- $cloneFolder = $vmView.parent
- # Build clone specification
- $cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
- $cloneSpec.Snapshot = $vmView.Snapshot.CurrentSnapshot
- # Make linked disk specification
- $cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
- $cloneSpec.Location.DiskMoveType = [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking
- # Create clone
- $vmView.CloneVM( $cloneFolder, $cloneName, $cloneSpec )
- # Write newly created VM to stdout as confirmation
- Get-VM $cloneName
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository