I need a simple PowerCli script to clone an ESXi 4.1 template on one datastore to a template on another datastore.
Bad luck, the PowerCLI 4.1 New-Template cmdlet didn't have the Template parameter yet.
An alternative is to temporarily convert the source template to a VM (with the Set-Template cmdlet), then do the New-Template with the VM parameter and when completed convert the VM back to a template (with the Set-VM cmdlet and the ToTemplate switch).
Some extra steps but that should work in PowerCLI 4.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Note: Discussion successfully moved from VMware ESXi™ 4 to VMware vSphere™ PowerCLI
You can clone a template and pass the target datastore.
Something like this
$tgtDatastore = "DS2"
New-Template -Name NewTemplate -Template OldTemplate -Datastore $tgtDatastore
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc, I get an error that says "A parameter cannot be found that matches Parameter Name Template"
You did replace my sample name "OldTemplate" with a name of one your templates ?
How does your line look ?
Or you could be running an older PowerCLI version ?
Which version do you have ? Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$tgtDatastore="ISCSiDatastore"
$newT="RHEL6GDc
$oldT="RHEL6GD"
New-Template -Name $newT -Template $oldT -Datastore $tgtDatastore -Confirm:$false
I'm running version 4.1 Update 1 and unfortunately cannot upgrade because I don't own the system.
Thanks for your assistance!
Bad luck, the PowerCLI 4.1 New-Template cmdlet didn't have the Template parameter yet.
An alternative is to temporarily convert the source template to a VM (with the Set-Template cmdlet), then do the New-Template with the VM parameter and when completed convert the VM back to a template (with the Set-VM cmdlet and the ToTemplate switch).
Some extra steps but that should work in PowerCLI 4.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, I don't want to do that for several reasons so I'll have to try and talk the system owners into upgrading the PowerCli to the latest version.
Can you not deploy a new VM from the template, migrate that VM to the new datastore, then convert that new VM back into a template?
Something like:
> $newVM = Get-Template "template-name" | New-VM
> $newVM | Move-VM -Datastore (Get-Datastore "destination-datastore-name")
> $newVM | New-Template
Just a thought.
Tocano, yes I believe I could do that however, I want to avoid converting the template to a VM and save as much time as possible in the cloning process
mainly because I have about 55 templates to clone to a different datastore and the process may be done frequently. Thanks
Might also take a look at the Copy-DatastoreItem cmdlet. Not sure if that would work for what you're wanting, but might be an option to try. Good luck.
Is it possible to keep the original VM date and time stamp when you clone it?
You mean the date and time on the files that constitute the VM ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, so if i look at the Vm files Modified On info in the datastore browser of the clone they match the original
I don't believe that happens even if you use New-Template. These are basically Linux filesystems. So a new file get a new modified date.
Yep, just tested with PowerCLI 5.5 using New-Template and the new copy gets new Modified dates.
I was thinking there may be a switch you could set in the PowerCLI script to preserve the date\time stamp similar to a DD copy.
Luc, is there such a switch to set in powercli when cloning templates that will retain the original creation dates? Also, I am running your script to add VMs to vCenter Inventory. It works fine on a few but, on the majority it is registering the vmdk file instead of the vmx. So instead of the VM name when registered I get the vmdk id string. Any thoughts?