How to migrate or move a template to different datastore?

On the first glace it should be relatively easy. One right-click on a template and migrate to different datastore. However there is no option to migrate template.

Moving the template to a different folder will not change storage placement. I thought that maybe I can just drag and drop the template to the destination datastore. But it did not work. 

To move template to different datastore one need to follow:

  1. Convert template to VM.
  2. vMotion VM to desire datastore.
  3. Convert VM to template.

Thankful we have a PowerCLI to help us with this task. Here is a small script to perform mentioned action:

Disconnect-VIServer *

Connect-VIServer your_vCenter

$template = Get-Template | where name -like *mnadp*

$Datastore = Get-Datastore | where name -Like *VTEST_0051*

$VM = $template | Set-Template -ToVM

Move-VM -VM $VM -Datastore $Datastore

$template = Set-VM $VM -ToTemplate -Confirm:$false
  • Firstly I like to disconnect from vCenters just in case.
  • Secondly I need to connect to one or more
  • $template – variable to get requested template with name contained mnadp
  • $Datastore – variable to get specific datastore, in my case with name contain VTEST_0051
  • $VM – is variable for converted template to VM
  • Move-VM – step to migrate VM to desire datastore
  • $template – converting VM back to template

Here is example of loop for multiple templates, of course you need to customize for your needs:

$templates = Get-Template

Foreach ( $template in $templates )


$VM = $template | Set-Template -ToVM

Move-VM -VM $VM -Datastore $Datastore

$template = Set-VM -VM $VM -ToTemplate -Confirm:$false


Please like and share to spread the knowledge in the community.

If you want to chat with me please use Twitter: @AngrySysOps

Visit my FB page:

Read my blog:

Subscribe to my channel :

Please leave the comment