Hi community,
I'm currently working on automating linked clones on a datastore cluster using this powershell function:
Function New-VMLinkedClone {
[CmdletBinding()]
param (
[string]$vCenterserver,
[string]$TargetVM,
[string]$vCenterUser,
[String]$vCenterPassword,
[string]$BaseVM,
[string]$TargetDatastore,
[string]$ResourcePool
)
### Connect vSphere
Connect-VIServer -server $vCenterserver -user $vCenterUser -Password $vCenterPassword
### Check if there is already a linkedclone snapshot for the clone and delete it
$SnapshotExists = Get-Snapshot -VM $BaseVM
if ($SnapshotExists.Name -eq "Linked-Snapshot-for-$TargetVMs") {
Write-Host "Linked-Snapshot-for-$TargetVMs already exists" -ForegroundColor red
Read-Host -Prompt "Press any key to delete the snapshot and continue or CTRL+C to quit"
$ExistingSnapshot = Get-Snapshot -VM $BaseVM -Name "Linked-Snapshot-for-$TargetVMs"
Remove-Snapshot -Snapshot $ExistingSnapshot -Confirm:$false
write-host "Old snapshot deleted" -ForegroundColor Green
}
### Create Master Snapshot
$SnapShot = New-Snapshot -VM $BaseVM -Name "Linked-Snapshot-for-$TargetVM" -Description "Snapshot for linked clones for $TargetVM" -Memory -Quiesce
Write-Host "Snapshot created for $BaseVM" -ForegroundColor Green
### Create Linked Clone
$DataStoreCluster = Get-DatastoreCluster -Name "$TargetDatastore"
$LinkedClone = New-VM -Name $TargetVM -VM $BaseVM -Datastore $DataStoreCluster -ResourcePool $ResourcePool -LinkedClone -ReferenceSnapshot $SnapShot
write-host "Linked clone $TargetVM created" -ForegroundColor Green
}
This function works well for single datastores, but when I specify a datastore cluster, I get this error:
New-VM The operation for the entity "" failed with the following message: "A specified parameter was not correct: CloneBase
Does any one have a clue about this error.
Thanks in advance.
Which PowerCLI version are you using?
The support for a datastorecluster on the Datastore parameter was only added recently.
Just tested it and in PowerCLI 11.2.0 it definitely works for me (in vSphere 6.7)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks you for ur reply.
I'm using the same version as yours:
PowerCLI Version
----------------
VMware PowerCLI 11.2.0 build 12483598
I'm still getting the same error
Can you attach a screenshot of the complete error message?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is the VM where you want to clone from living on that same datastorecluster?
It seems to be an issue with the snapshot the linked clone would use, not so much the datastorecluster.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes they both live in the same datastore cluster
Is there any additional information in the vpxd.log around the time you run the script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference