PowerCLI

 View Only
Expand all | Collapse all

Moving templates with Move-Template cmdlet

  • 1.  Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 09:33 AM

    Hello everyone,

    I have 2 clusters in one datacenter and I'm moving all the resources from the old cluster to the new one (EVC enabled cluster).

    I have to move every templates and rather doing it manually I would like to do it in PowerShell...

    The problem is that I'm struggling with Move-Template because I cannot figure out how to pass the right value for the -Destination parameter. This parameter is waiting for a VIContainer object.

    So the question is : "How to create a VIContainer object in order to make it work ?"

    The help associated to Move-Template is very poor, only one example which doesn't help at all.

    I'm using PowerCLI 4.0 U1 - VC 3.5 U6.

    Thanks in advance guys,

    Arnaud PETITJEAN

    PowerShell MVP



  • 2.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 09:38 AM

    A VIContainer is a base object.

    You can use for example a folder as the destination

    Get-Template | Move-Template -Destination (Get-Folder -Name  "New-Folder")
    

    A Datacenter also has the VIContainer as a base class, so you can also do

    Get-Template | Move-Template -Destination (Get-Datacenter -Name  "MyDatacenter")
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 09:46 AM

    Thanks for your reply Luc.

    ...but as far as I know templates are associated to one host. So my problem is "how to specify the host I want the template attached to ?".

    So I think I need to specify a destination with the server name inside.

    Arnaud Petitjean



  • 4.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 09:49 AM

    If you want to have more options with migrating a template, you have to convert the template to a VM first. Then migrate the VM. And finally convert the VM back to a template. See: PowerCLI: Move-Template for more information.

    Regards, Robert



  • 5.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 11:22 AM

    Thanks Robert for your answer.

    Yes I've seen your blog post, but I was wondering since the availability of the native Move-Template if it could be simpler.

    Arnaud Petitjean

    PowerShell MVP

    http://powershell-scripting.com



  • 6.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 09:52 AM

    You're right, but I'm refereing to the "blue" folders.

    These are the ones you see "VMsand Templates".

    If you want to migrate the template from one host to another then that is not possible with the current Move-Template implementation.

    You have to first convert the template to a VM, do a Move-Vm and convert the VM back to a template.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 7.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 11:20 AM

    Okay, I see...

    As my VMs are stored on a SAN, I noticed that I only have to unregister the template from the inventory, then register the template from the datastore where it is stored (then right click on the vmtx file / Add to inventory). This way, I can specify the host which will "handle" the template.

    Is that possible with PowerCLI ?

    Arnaud PETITJEAN



  • 8.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 11:29 AM

    You can unregister a template with the Remove-Template cmdlet. To register the template again, take a look at Luc's Raiders of the Lost VMX.



  • 9.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 11:36 AM

    Just a small addition. Don't forget to use the -DeleteFromDisk:$false parameter with the Remove-Template cmdlet.

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 10.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 12:10 PM

    From Get-Help I got the understanding that -DeleteFromDisk:$false is the default for the Remove-Template. But you made me doubt. So I ran a little test. I created a new template and removed the template with Remove-Template without the -DeleteFromDisk parameter. And the template's files where still on the datastore. So you don't have to use the -DeleteFromDisk:$false parameter to keep the files. But of course if you use the parameter it makes more clear what you want. :smileywink:



  • 11.  RE: Moving templates with Move-Template cmdlet

    Posted Jul 01, 2010 12:31 PM

    You're right but I don't trust defaults :smileywink:

    More so since the documentation doesn't mention it.

    ____________

    Blog: LucD notes

    Twitter: lucd22