VMware Cloud Community
OsburnM
Hot Shot
Hot Shot

Automate Cloning Templates Across vSphere DataCenters

Greetings all--  looking for some ideas here.

Have a bunch of "master templates" at our primary datacenter.  I'd like to clone all of these to my remote site datacenters within the same vsphere.

I'd like to avoid having to manually delete the old templates then "clone" the master templates to the remote sites, then convert them back to templates again.

Ideas/suggestions?   I tried just cloning the templates once, then doing an update to my master templates and simply just copying the vmdks (PowerCLI) but that didn't work.

Thanks!

Tags (3)
2 Replies
mattboren
Expert
Expert

Hello, OsburnM-

This seems pretty do-able using PowerCLI and the standard *Template cmdlets.

Rather than the manual deletion of the old templates and manual cloning, you could use the Remove-Template cmdlet for removing the old templates, and then the New-Template cmdlet to clone the master to each of the given datacenters.

A rough example, to give an idea:

$strOldTemplateName = "myTemplate01"    ## name of old template in remote datacenters to delete
$strMasterTemplateName = "masterTempl"    ## name of master template to clone
$strNewTemplateName = "myTemplate02"    ## name for new template in remote datacenters
#
# array of destination datacenter names
$arrDCenterNames = "westCoast","EastCoast","SouthSide"
$arrDCenterNames | %{
   
$strThisDCenterName = $_
   
## get this datacenter object
    $oThisDatacenter = Get-Datacenter $strThisDCenterName
   
## delete the old template in this datacenter
    Get-Template $strOldTemplateName -Location $oThisDatacenter | Remove-Template -DeletePermanently -Confirm:$false
   
## clone the master template to this datacenter
    New-Template -Template $strMasterTemplateName -Name $strNewTemplateName -Location $oThisDatacenter -Datastore "templates01" -RunAsync
}
## end foreach-object

You would want to test/tweak this to fit your need, but something like that should get you close.  That helpful?

TedSpinks
Contributor
Contributor

mattboren, perfect, this is surprising hard to find!

OsburnM, I remember talking to you about this a couple years ago!!  Glad you posted the question and got an answer 😉  Funny how this keeps coming up...

Reply
0 Kudos