Automation

 View Only
  • 1.  Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 11:01 AM

    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.



  • 2.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 11:21 AM

    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)



  • 3.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 11:34 AM

    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



  • 4.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 11:52 AM

    Can you attach a screenshot of the complete error message?



  • 5.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 11:59 AM
      |   view attached

    Please find the screenshot attached.



  • 6.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 12:08 PM

    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.



  • 7.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 12:14 PM

    Yes they both live in the same datastore cluster



  • 8.  RE: Powercli Linked clones | Datastore cluster

    Posted Mar 08, 2019 01:56 PM

    Is there any additional information in the vpxd.log around the time you run the script?