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.