SharePoint 2010 is a great platform in terms of features and functionalities related to the document management area. One of the most important features is the ability for the users and for the administrators to create a well established and structured set of terms that can be used to properly classify all the documents stored in a SharePoint site, thus creating a consistent taxonomy that can be used all over a SharePoint company's implementation and improving search results.
In this article we'll illustrate the main features of the SharePoint Managed Metadata Service Application (also known as the term store) and how it can be manipulated and managed via Powershell.

Back to top

What is the Term Store?

The term store (whose "real name" is Managed Metadata Services) is a hierarchical collection of terms that can be used to describe various types of items, such as documents and list items. The term store allows for the organization of terms, lists and classifications to be leveraged across multiple SharePoint web applications or site collections.
Managed Metadata Services is a SharePoint 2010 service application, so it can be accessed and managed through Central Administration: in the Application Management section click Manage Service Applications, then click Managed Metadata Service.

Back to top

Connecting to the Term Store

The first step to take when manipulating the term store is accessing the Managed Metadata service application (or the service applications, since you can have more than one term store in your SharePoint installation) that represents the global term store available in SharePoint and that contains all of the stored terms groups.
Accessing the service application requires using a variable that will store the result of the execution of the Get-SPTaxonomySession cmdlet, that will be passed as a parameter the address of the SharePoint site collection hosting the term store: open the SharePoint Management Shell, type and run the following command

$SPTax = Get-SPTaxonomySession -Site http://siteaddress

The $SPTax variable will store a Microsoft.SharePoint.Taxonomy.TaxonomySession object, containing the set of all the available metadata term stores for the specified site collection. The members (that you can get by piping the Get-Member cmdlet with the $SPTax variable) of the TaxonomySession object will allow you to access all the available term stores wrapped by the object: for example, you can access the site collection default term store by means of the DefaultSiteCollectionTermStore property or you can retrieve the collection of the term stores associated with the web application of the current site collection by means of the collection represented by the TermStores property. Since you must pass through the whole term store hierarchy until get every single stored term set or even term, you need to have a reference to the set of the available term stores. For the sake of convenience and reuse, you can store a reference to the set of term stores in a variable as in the following

$SPTSs = $SPTax.TermStores

By using this reference you can walk through the term store hierarchy, thus accessing the terms groups (and the terms sets and every single term within them) stored in a term store.
Back to top

Getting the Term Groups

Connect to all term groups and store a list of them into the $SPTermGroups variable using the following PowerShell Command

$SPTermGroups = $SPTax.TermStores.Groups
Optionally, you can filter on the group you need using the Where-Object Command
$SPTermGroup = $SPTax.TermStores.Groups | Where-Object {$_.Name -eq "Intranet"}

Whether or not to use this filter depends on the fact that a full term store export operation is required or that we have to export only a limited set of groups among the ones currently stored in the Managed Metadata Service Application: for example, it could be possible to have a .CSV file listing the set of term groups to be exported and pass this file's name as a parameter to a script that will actually perform the export operation, thus making the script export only the specified term groups.

Back to top

Getting the Term Sets

Having accessed the set of groups stored in the Managed Metadata service application, you can go down a level further and access the term sets within a term group: each term set (as the name implies) contain a set of terms. Provided that you have stored a reference to a term store group (as you have just seen in the previous section), you can get access to the whole set of term sets by using the following Powershell command

$SPTermSets = $SPTermGroup.TermSets

Optionally, you can filter on the term set you need using the Where-Object Command

$SPTermSet = $SPTermGroups.TermSets | Where-Object {$_.Name -eq "DBMS"}
Back to top

Getting the Terms

After getting the complete set of term sets contained in a term group, you can get all of the terms contained in the term sets by using the following

$SPTerms = $SPTermSet.Terms

Then you can iterate on all the terms contained in the term set and getting their properties' values.

Back to top

Complete Sample: Exporting the Term Store to a XML File 

Back to top

Community Content

See Also

NOTE: the following links are external to TechNet Wiki.

Back to top

Other Languages

This article is also available in the following languages:

Italian (it-IT)