VMware Cloud Community
arnaudp
Contributor
Contributor

Moving templates with Move-Template cmdlet

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

0 Kudos
10 Replies
LucD
Leadership
Leadership

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


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

0 Kudos
arnaudp
Contributor
Contributor

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

0 Kudos
RvdNieuwendijk
Leadership
Leadership

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

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

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


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

0 Kudos
arnaudp
Contributor
Contributor

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

0 Kudos
arnaudp
Contributor
Contributor

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

0 Kudos
RvdNieuwendijk
Leadership
Leadership

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.

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

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

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
RvdNieuwendijk
Leadership
Leadership

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. Smiley Wink

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

You're right but I don't trust defaults Smiley Wink

More so since the documentation doesn't mention it.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos