Script to Import/Export Metadata Termstore

Recently I’ve been using the Managed Metadata Store in SharePoint 2010 and been amazed by the lack of proper import/export functionality.

It feels like a blast from the past to be able to only import a CSV file… CSV?!? What happened to proper XML? What happened to Export? What happened to being able to transfer (meta)data between farms (like test and production) since the builtin Import insists on creating new TermSets and not update existing ones (and yes your managed metadata linked site columns do in fact store a strong reference, not just a name, so you’ll loose the link).

I couldn’t find any existing Powershell commandlets to the rescue either.

I couldn’t readily bing 😉 any usable scripts for this.

What I did

So I built a powershell script to take a CSV file and import it into the Term Store and merge it with any existing term store already there.

CSV?!?? Yeah…

Point is then you can still use the CSV file you likely already hold. You can use the TermSetImporter to export CSV files from your existing environment.

If you are starting Greenfield, then I recommend to use excel with some macros to create the Term Sets (then your users can create them instead of you) or you might just let your users loose in the term store manager.

How to use

First download my small script and the sample excel and CSV files.

Second, fire up powershell (on a SharePoint server), write:

. ./MergeTermSets.ps1 csvfile groupname urlForASharePointSite

Do remember the “dot space” at the start of the line. The second “./” is just the path for the ps1 file in this case.

The urlForASharePointSite is optional and will default to http://localhost:2010 which likely corresponds to a valid SharePoint Central Admin site on 50% of all SharePoint installations. Watch the output log. If something goes wrong it’s likely that you should have a look in your CSV file for errors and/or whether or not the managed metadata store is connected properly.


  • I’ve tried to do some tricks to handle encoding properly and I also trim spaces which really causes the term store to stumble (it will trim spaces and every subsequent comparison the script might do will fail).
  • Note that LCID and the parent Terms need to be set on every line in the excel sheet. Don’t blame me I didn’t make that part 😉
  • Terms are only added not updated, i.e. I don’t try to keep stuff like descriptions in sync
  • No fancy stuff, no merging, no deletions, deprecation etc.

Hope it’s useful for you too.


About Søren Nielsen
Long time SharePoint Consultant.

6 Responses to Script to Import/Export Metadata Termstore

  1. kaushalecm says:

    hi, nice article, you said: managed metadata linked site columns do in fact store a strong reference, not just a name, so you’ll loose the link…..
    so does using csv method keep the links with site column?

    • Søren Nielsen says:

      Using my script to merge the term stores from a csv file does not change existing values and therefore preserves the links.

      However if you do a site collection restore (I’m not sure if that’s what you are implying too) between farms I doubt it will work. I have not tested that.

  2. Great stuff, Søren, really appreciate it. Found a minor bug, though. The main loop assigns the current line from the csv to the $line variable, while the empty variable $currentline is used in the call to GetLineTermPath later on (instead of $line).

  3. Bardo says:

    Another implementation of PowerShell terms export/import is here:

  4. One-Man SharePoint Team says:

    Søren, wanted to say thanks for posting your scripts; your code & the notes added by Anders helped me get metadata merges working much faster than I could have otherwise. Very useful contribution!

  5. Scott says:

    Thank you for this code.
    There is a spot for improvement. At about line 75 “$term = $parentNode.Terms[$termValue]
    Replace $termValue with [Microsoft.SharePoint.Taxonomy.TaxonomyItem]::NormalizeName($termValue).
    I was getting errors when I had terms with ampersand (&) in the term. This will fix that issue.

    Again, thank you. I am glad I didn’t have to write this all on my own.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: