You are currently browsing the Kristof Kowalski blog archives for March, 2011


SharePoint 2010 Export Managed Metadata Terms from the Term Store

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

# File and Drectory Location
$date = get-date -Format yyyyMMdd
$dirLocation = "\\server\share\Taxonomy\Terms\"
New-Item ($dirLocation + $date) -type directory | Out-Null

# Connect to Central Admininistration Site
$taxonomySite = Get-SPSite http://server:31337

# Connect to Term Store in the Managed Metadata Service Application
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$termStore = $taxonomySession.TermStores["Managed Metadata Service (Enterprise)"]

# Connect to the Profiles Term Group
$termStoreGroup = $termStore.Groups["Profiles"]

# Export Terms as .csv for each Term Set
foreach ($termSet in $termStoreGroup.TermSets.GetEnumerator()) {
$termSet.Terms | select Name, Owner, CreatedDate, LastModifiedDate | Export-Csv ($dirLocation + $date + "\Terms-" + $termStore.Groups["Profiles"].Name + "-" + $termSet.Name + ".csv")
}

# Connect to the System Term Group
$termStoreGroup = $termStore.Groups["System"]

# Export Terms as .csv for each Term Set
foreach ($termSet in $termStoreGroup.TermSets.GetEnumerator()) {
$termSet.Terms | select Name, Owner, CreatedDate, LastModifiedDate | Export-Csv ($dirLocation + $date + "\Terms-" + $termStore.Groups["System"].Name + "-" + $termSet.Name + ".csv")
}

With the above script that will export all your Terms with the Name, Term Owener, 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-Previous Employers.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.

Cheers,

Kristof Kowalski | kristof@kowalski.ms