VMware Cloud Community
tumbi1
Contributor
Contributor
Jump to solution

Trying to create a linked clone

Hello all,

I am a newbie to using PowerCLI, and I have a new evaluation setup of vCenter and ESXi for testing the feasibility of using linked clones.  I have tried running the following script to create a clone, but only get the text I have pasted below the result heading.  It seems pretty basic, so not sure what is going wrong?

Cheers,

Mark.

SCRIPT;

$sourceVM = Get-VM "Test" | Get-View

$cloneName = "Testclone"

$cloneFolder = $sourceVM.parent

$cloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec

$cloneSpec.Snapshot = $sourceVM.Snapshot.CurrentSnapshot

$cloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec

$cloneSpec.Location.DiskMoveType = [Vmware.Vim.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking

$sourceVM.CloneVM_Task( $cloneFolder, $cloneName, $cloneSpec )

RESULT;

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> .\basicc

lonehino2.ps1

Type                                    Value

----                                    -----

Task                                    task-97

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

In your script you use the CloneVM_Task() method that creates a vSphere task. The output of the script is the task created. You can use the CloneVM() method instead. The CloneVM() method works synchronously and returns after the clone is created.

If you keep the CloneVM_Task() method, you can use the Get-Task cmdlet to retrieve the status of the task. You can use the Wait-Task cmdlet to wait until the task is completed.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
1 Reply
RvdNieuwendijk
Leadership
Leadership
Jump to solution

In your script you use the CloneVM_Task() method that creates a vSphere task. The output of the script is the task created. You can use the CloneVM() method instead. The CloneVM() method works synchronously and returns after the clone is created.

If you keep the CloneVM_Task() method, you can use the Get-Task cmdlet to retrieve the status of the task. You can use the Wait-Task cmdlet to wait until the task is completed.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos