Manage Managed Metadata Terms in Microsoft SharePoint Server 2010

Introduction

This script can manage managed metadata terms in Microsoft SharePoint Server 2010. You can use this script to get terms, add terms or remove terms.

Scenarios

In a real world, a lot of people ask the possibility of managing managed metadata terms by using Windows PowerShell. Since administrators need to manage lot of terms, they really need to find a script to reduce their workload.

Script

This script contains the following advanced functions:

You can use this script in the following way.

  1. Open SharePoint 2010 Management Shell with a proper account that has sufficient permission to manage managed metadata terms.
  2. Run Import-Module cmdlet to import this module file.
    Import-Module filepath\scriptname.psm1

Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.

PowerShell
Edit|Remove
foreach ($termNamein$Name) { 
    $spTerms = $spTermStore.GetTerms($termName,$DefaultLabelOnly,$MatchOption,$ResultCollectionSize,$TrimUnavailable) 
    if ($spTerms-ne $null) { 
        foreach ($spTermin$spTerms) { 
            $PSCmdlet.WriteObject($spTerm) 
        } 
    } else { 
        $errorMsg = $Messages.CannotFindSpecificTerm 
        $errorMsg = $errorMsg-$termName$customError = New-OSCPSCustomErrorRecord ` 
        -ExceptionString $errorMsg ` 
        -ErrorCategory NotSpecified -ErrorID 1 -TargetObject $pscmdlet$pscmdlet.WriteError($customError) 
    } 
}

 

Examples:

Example 1: How to display help about Get-OSCSPTaxonomyTerm
To display help about Get-OSCSPTaxonomyTerm, please run this command.
Get-Help Get-OSCSPTaxonomyTerm -Full

Example 2: How to get specific managed metadata terms.
To return specific managed metadata terms, please run this command.
Get-OSCSPTaxonomyTerm -SiteUrl "http://sitename" -TermStoreName "Managed Metadata Service"-Name"Term01","Term02"

Example 3: How to get specific managed metadata terms that starts with "N".
To return specific managed metadata terms that starts with "N", please run this command.
Get-OSCSPTaxonomyTerm -SiteUrl "http://sitename" -TermStoreName "Managed Metadata Service"-Name "N" -MatchOption StartsWith

Example 4: How to add managed metadata terms.
To add managed metadata terms, please run this command.
Add-OSCSPTaxonomyTerm -SiteUrl "http://sitename" -TermStoreName "Managed Metadata Service" -TermSetName "Terms" -Name "New Term 04","New Term 05","New Term 06" 

Example 5: How to remove managed metadata terms.
To remove managed metadata terms, please run this command.
Remove-OSCSPTaxonomyTerm -SiteUrl "http://sitename" -TermStoreName "Managed Metadata Service" -Name "New Term 04","New Term 05","New Term 06" 

Additional Resources

Technical Resources
Windows PowerShell Advanced Function
Microsoft.SharePoint.Taxonomy Namespace

Forum Threads:
http://social.technet.microsoft.com/Forums/fi/sharepointadminprevious/thread/4e630892-007f-42fa-bea1-620d749f3923
http://social.technet.microsoft.com/Forums/en/sharepointadminprevious/thread/f00fee5b-06f3-4acf-b905-4503208de9f9