Last active
April 22, 2016 15:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
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