#The function below installs the PowerShell Snap-ins for SharePoint. This will only run if its not already been done.
function Install-SharePoint
{
IF ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $
null
)
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
function Get-TermStore
#call the adding of PSSnap-in
Install-SharePoint
#Connect to Central Admin
$taxonomySite =
get
-SPSite http:
//site
#Connect to Term Store in the Managed Metadata Service Application
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$termStore = $taxonomySession.TermStores[
"TermStore"
]
#Connect to the Group and Term Set
$termStoreGroup = $termStore.Groups[
"TS GROUP"
#Gets TermSet and lists the Terms under it by Name
$termSet = $termStoreGroup.TermSets[
"TERMSET IN GROUP"
#Call rename function
Rename-Term
function Rename-Term{
$allTerms = $termSet.getAllTerms()
foreach
($term
in
$allTerms)
try
$name = $term.name
$id = $term.id
#I only want all terms that are more than 6 characters in length as I am going to check for the first 6 letters
if
($name.length -lt 6)
{}
else
$code = $name.substring(0,6)
#using Regex I want to know if the term starts with 3 letters and has 3 numbers after
($code -match
'[A-Z]{3}[0-9]{3}'
($code.substring(0,3) -eq $initials)
#Using Regex I want the first 3 letters from the name and I am going to change them (replace) with my new value
$newName = $name -replace
'^[A-Z]{3}'
, $newText
write-host
"current name: $name"
"GUID: $ID"
$term.name = $newName
$termStore.CommitAll()
"New name: $newName"
-foreground
"green"
""
$taxonomySite.Dispose()
catch
{$error[0].Exception}