Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Last active April 22, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zsoldier/a4baf070b0e663d8c9aa54e73a595736 to your computer and use it in GitHub Desktop.
Save Zsoldier/a4baf070b0e663d8c9aa54e73a595736 to your computer and use it in GitHub Desktop.
This is a script you can use to re-register multiple templates to your vCenter's inventory. It will simply get a list of templates, their folder location, host, etc, remove it from inventory and re-add it back exactly where it was.
<#
Re-register templates that are locked
KB Reference: https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2037005
#>
Import-Module vmware.vimautomation.core
Connect-VIServer NameofyourVcenter
$TargetTemplates = Get-Template "NamePatternOfTemplateOrRemoveThisIfYouWantToTargetAllTemplates*" -server $Global:DefaultVIServer
Foreach ($Template in $TargetTemplates)
{
$DatastorePath = $Template.extensiondata.summary.config.VmPathName
$Location = Get-Folder -id $Template.folderid
$VMHost = Get-vmhost -id $template.hostid
$TemplateName = $Template.Name
Remove-Template -Template $Template -Confirm:$False
New-Template -VMHost $VMHost -Name $TemplateName -Location $Location -TemplateFilePath $DatastorePath -Confirm:$false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment