A couple of days ago I found a really great PowerCLI script that move templates i vSphere. Awesome post and script by afokkema at ict-freak.nl!
Storage vMotion is a great feature to Move your VMs to other datastores. But what if you want to move your Templates?
In the current version of vSphere there is no option within the Client
function Move-Template{
param( [string] $template, [string] $esx, [string] $datastore)
if($template -eq ""){Write-Host "Enter a Template name"}
if($esx -eq ""){Write-Host "Enter an ESX hostname"}
if($esx -ne "" -and $datastore -eq ""){$vmotion = $true}
if($datastore -ne ""){$svmotion = $true}
Write-Host "Converting $template to VM"
$vm = Set-Template -Template (Get-Template $template) -ToVM
if($svmotion){
Write-Host "Migrate $template to $esx and $datastore"
Move-VM -VM (Get-VM $vm) -Destination (Get-VMHost $esx) `
-Datastore (Get-Datastore $datastore) -Confirm:$false
(Get-VM $vm | Get-View).MarkAsTemplate() | Out-Null
}
if($vmotion){
Write-Host "Migrate $template to $esx"
Move-VM -VM $vm -Destination (Get-VMHost $esx) -Confirm:$false
($vm | Get-View).MarkAsTemplate() | Out-Null
}
}
The function above can be used to move a single template via:
Move-Template <template> <esxhost> <datastore>
Source: http://ict-freak.nl/2010/01/21/powercli-move-template/
