PowerCLI

 View Only
Expand all | Collapse all

Clone Template to template

  • 1.  Clone Template to template

    Posted Nov 12, 2013 03:52 PM

    I need a simple PowerCli script to clone an ESXi 4.1 template on one datastore to a template on another datastore.



  • 2.  RE: Clone Template to template

    Posted Nov 12, 2013 03:55 PM

    Note: Discussion successfully moved from VMware ESXi™ 4 to VMware vSphere™ PowerCLI



  • 3.  RE: Clone Template to template

    Posted Nov 12, 2013 05:27 PM

    You can clone a template and pass the target datastore.

    Something like this

    $tgtDatastore = "DS2"
    New-Template -Name NewTemplate -Template OldTemplate -Datastore $tgtDatastore


  • 4.  RE: Clone Template to template

    Posted Nov 12, 2013 06:02 PM

    Luc, I get an error that says "A parameter cannot be found that matches Parameter Name Template"



  • 5.  RE: Clone Template to template

    Posted Nov 12, 2013 08:37 PM

    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



  • 6.  RE: Clone Template to template

    Posted Nov 13, 2013 10:17 AM

    $tgtDatastore="ISCSiDatastore"

    $newT="RHEL6GDc

    $oldT="RHEL6GD"

    New-Template -Name $newT -Template $oldT -Datastore $tgtDatastore -Confirm:$false



  • 7.  RE: Clone Template to template

    Posted Nov 13, 2013 10:21 AM

    I'm running version 4.1 Update 1 and unfortunately cannot upgrade because I don't own the system.

    Thanks for your assistance!



  • 8.  RE: Clone Template to template
    Best Answer

    Posted Nov 13, 2013 02:12 PM

    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



  • 9.  RE: Clone Template to template

    Posted Nov 13, 2013 02:59 PM

    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.



  • 10.  RE: Clone Template to template

    Posted Nov 13, 2013 04:25 PM

    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.



  • 11.  RE: Clone Template to template

    Posted Nov 13, 2013 04:35 PM

    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



  • 12.  RE: Clone Template to template

    Posted Nov 13, 2013 04:42 PM

    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.



  • 13.  RE: Clone Template to template

    Posted Nov 14, 2013 05:52 PM

    Is it possible to keep the original VM date and time stamp when you clone it?



  • 14.  RE: Clone Template to template

    Posted Nov 14, 2013 06:22 PM

    You mean the date and time on the files that constitute the VM ?



  • 15.  RE: Clone Template to template

    Posted Nov 14, 2013 08:00 PM

    Yes, so if i look at the Vm files Modified On info in the datastore browser of the clone they match the original



  • 16.  RE: Clone Template to template

    Posted Nov 14, 2013 08:15 PM

    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.



  • 17.  RE: Clone Template to template

    Posted Nov 18, 2013 10:47 AM

    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.



  • 18.  RE: Clone Template to template

    Posted Nov 22, 2013 02:54 PM

    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?