Skip to content

Instantly share code, notes, and snippets.

@BenNeise
Created October 29, 2013 14:20
Show Gist options
  • Save BenNeise/7215567 to your computer and use it in GitHub Desktop.
Save BenNeise/7215567 to your computer and use it in GitHub Desktop.
# Get all templates
$objTemplates = Get-Template
# Loop through the templates
ForEach ($objTemplate in $objTemplates){
# Set the $StrInterimTemplateName variable to the template name, replacing the string "Tmpl" with an empty string
$StrInterimTemplateName = ($objTemplate.Name -replace("Tmpl",""))
# As the string we've just removed might be anywhere in the name, we need to replace double spaces with single
$StrInterimTemplateName = ($StrInterimTemplateName -replace(" "," "))
# And also remove trailing spaces from the start, or the end of the string
$StrInterimTemplateName = $StrInterimTemplateName.Trim()
# Display on screen what we're doing (as the "Set-Template" with -WhatIf isn't very clear
Write-Host Changing `[($objTemplate.Name)`] to `[ Tmpl $StrInterimTemplateName `]
# Change the Template Name to the $StrInterimTemplateName variable preceeded by "Tmpl", uncomment the #-WhatIf if testing
Set-Template -Template $objTemplate -Name "Tmpl $StrInterimTemplateName" #-WhatIf
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment