SharePoint 2010 Export Managed Metadata Terms from the Term Store

Posted on Posted in SharePoint

As part of our SharePoint 2010 deployment here, we make extensive use of the new Managed Metadata Service Application. To ensure we have concise and correct terms we have Term Store Managers that check on a weekly basis the validity of these terms. Some of the tests they check is duplicaiton or terms, correct spelling and just general term lifecycle itself.

I’ve checked around and there are plenty of scripts around that instruct you to upload and create terms through PowerShell, but we needed a quick way to export our current terms and find out who created the term and when. So here’s a litte script you can schedule to run each week.

One thing to check for is the name of the Term Store you bind, which shoukd be listed via the Get-SPTaxonomySession cmdlet.

# Add SharePoint PowerShell Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

# File and Directory Location
$dirLocation = "C:\Temp\Terms\"
$date = get-date -Format yyyyMMdd
New-Item ($dirLocation + $date) -Type Directory | Out-Null
$file = New-Object System.IO.StreamWriter(($dirLocation + $date) + "\Terms.csv")

# Connect to site with MMS service connection
#$taxonomySite = Get-SPSite "http://site"
$taxonomySite = Get-SPSite -Limit 1

# Connect to Term Store in the Managed Metadata Service Application
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$taxonomyTermStore = $taxonomySession.TermStores | Select Name
$termStore = $taxonomySession.TermStores[$taxonomyTermStore.Name]

# Ampersands are stored as full width ampersands within the MMS database.
[Byte[]] $amp = 0xEF,0xBC,0x86

# CSV headers
$file.Writeline("Term Name,Id,Owner,CreatedDate,LastModifiedDate")

# Term counter
$i = 0

foreach ($group in $termStore.Groups) {

foreach ($termSet in $group.TermSets) {

foreach ($term in $termSet.GetAllTerms()) {
[Byte[]] $amp = 0xEF,0xBC,0x86;
$file.Writeline("""" + $term.Name.Replace([System.Text.Encoding]::UTF8.GetString($amp), "&") + """" + "," + $term.Id + "," + $term.Owner + "," + $term.CreatedDate + "," + $term.LastModifiedDate);
Write-Host -ForegroundColor Cyan "# Exporting TermSet: " -NoNewline
Write-Host -ForegroundColor White $termSet.Name -NoNewline
Write-Host -ForegroundColor Cyan " Term: " -NoNewline
Write-Host -ForegroundColor White $term.Name -NoNewline
Write-Host -ForegroundColor Green " – Done"

Write-Host -ForegroundColor Cyan "# Exported " -NoNewline
Write-Host -ForegroundColor Green $i -NoNewline
Write-Host -ForegroundColor Cyan " terms"

With the above script that will export all your Terms with the Term Name, Id, Term Owner, Creation Date and Last Modificaiton Date. Our Term Store Managers like to review the terms on a weekly basis so all that needs to be run later is the following couple of lines per each Term Set;

# If you want see what terms have changed since last export, ie 7 days
$dateToCompare = (Get-date).AddDays(-7)
Import-Csv ‘.\Terms.csv’ | Where-Object {$_.LastModifiedDate -gt $dateToCompare} | Sort-Object {$_.LastModifiedDate} -Descending

I’ll alter the above script later to iterate through all the Term Set csv files to then export the changes in a further update. For now, enjoy.


Kristof Kowalski |

4 thoughts on “SharePoint 2010 Export Managed Metadata Terms from the Term Store

  1. Hi Kristof,

    My SP engineer says this script does not pick up nested terms (haven’t looked at the code myself yet).  Do you have a version that does?

    Also can it export all labels (synonyms), and the GUID for the term?  These would be very helpful for maintaining a master file with information that the MMS term store does not support, and for moving term stores between systesm.

    Many thanks in advance.


    1. Hi there,

      Yup.. managed to fix the script now so it dumps out the terms using the GetAllTerms() method. Silly mistake before. Just about to post another script that exports to csv per Term Level too.

  2. Hi

    Is is possible to move terms under one term group/parent term to another term group / parent_term_with_same_name, Using PowerShell. 

    I have 400 to move and it is so tedious via the term store management 

Comments are closed.