VMware/Linked Clone Powershell Script

New-LinkedClone.ps1

 * 1) Requires -version 2


 * 1) TITLE: 	New-LinkedClone.ps1
 * 2) AUTHOR:	Hal Rottenberg
 * 3) Adapted from a technique published originally by Keshav Attrey http://www.vmdev.info/?p=40
 * 4) Also see William Lam's Perl script: http://engineering.ucsb.edu/~duonglt/vmware/vGhettoLinkedClone.html
 * 5) 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

$cloneSnap = $vm | New-Snapshot -Name "Clone Snapshot"
 * 1) Create new snapshot for clone

$vmView = $vm | Get-View
 * 1) Get managed object view

$cloneFolder = $vmView.parent
 * 1) Get folder managed object reference

$cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec $cloneSpec.Snapshot = $vmView.Snapshot.CurrentSnapshot
 * 1) Build clone specification

$cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec $cloneSpec.Location.DiskMoveType = [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking
 * 1) Make linked disk specification

$vmView.CloneVM( $cloneFolder, $cloneName, $cloneSpec )
 * 1) Create clone

Get-VM $cloneName
 * 1) Write newly created VM to stdout as confirmation

Clone-XP.ps1
$i = 1

do { .\New-LinkedClone.ps1 XP-Test XP-Clone1-$i $i++ } while ($i -le 49)

Clone-XP-SubPrime.ps1
Connect-VIServer -Server 192.168.2.4 -User fusion\administrator -Password Fusion10

$i = 1

do { .\New-LinkedClone.ps1 XP-Sub-Prime1 XP-Sub1-Clone$i $i++ } while ($i -le 24)

$i = 1

do { .\New-LinkedClone.ps1 XP-Sub-Prime2 XP-Sub2-Clone$i $i++ } while ($i -le 25)

Disconnect-VIServer -Server * -Confirm:$False