BrianRTS
Enthusiast
Enthusiast

Cloning VM/vApp to different DataStore

Jump to solution

Hi all,

I am working off of Ruben garcia's excellent linked clone scripts and one thing I am trying to add is to have the vApp created on a differnt datastore.

# Clone and move vms
foreach ($vm in $vms){
     $vm=$vm| get-view
     $vmname=$cloneName +"-" + $vm.name
     .\LcloneVM $vm.name -cloneName "$vmname"  -PortGroup "$PortGroup"
     get-vm -name $vmname | move-vm -destination $vapp;
 
The VM's are getting cloned and then inserted in the vApp name passed along as a parameter but I cant figure out how to have the vApp get created on a datastore that I specify. Right now the vApp gets created on the same datastore where the linked clones reside. I can move them after from the UI using the migrate command but I want to automate it if possible.
I thought the following line would work but the vApp fails during creation so the move-vm command fails later on.
 
# Create vApp
$vapp = $host_name | new-vapp -name "$cloneName" -Datastore "ThinDiskTesting";

I'm at a loss to what im doing wrong

Message was edited by: BrianRTS - Fix formatting

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You can specify the datastore where you want to create linked clone delta files.

This requires a small change to Ruben's script

# Generate specs for clone 
$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
$cloneSpec.Location.Datastore = (Get-Datastore -Name $tgtDatastoreName).ExtensionData.MoRef

The Datastore property is used to indicate where the clone should be located.

Or do you want create the clones and then move them ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

You can specify the datastore where you want to create linked clone delta files.

This requires a small change to Ruben's script

# Generate specs for clone 
$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
$cloneSpec.Location.Datastore = (Get-Datastore -Name $tgtDatastoreName).ExtensionData.MoRef

The Datastore property is used to indicate where the clone should be located.

Or do you want create the clones and then move them ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
BrianRTS
Enthusiast
Enthusiast

Thanks! I'll make the change to the vApp script and test on Tuesday. Will assign points ASAP

Sent from my iPad

0 Kudos
LucD
Leadership
Leadership

No hurry, remember that you will have to provide the datastorename in this $tgtDatastoreName variable.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference