In SharePoint we have the Term Store for managing reusable terms. Besides tenant level term groups, which are available to all site collections, each site can have their own group. There are situations when you need to move term sets between different site collections or to/from the tenant level. If the terms you are moving are in use by site fields it is important to maintain the term IDs. Luckily, when creating new terms with code you can specify the ID. But all terms are stored in the same database, so you can’t pick an ID that is already in use somewhere else. Here is how to manage such a move.
In this example I’m moving a local term group to the tenant level using PnP PowerShell:
- Extract the terms:
Export-PnPTermGroupToXml -Out "C:\Temp\terms.xml" -Identity "Site Collection - contoso.sharepoint.com-sites-MySiteCollection"
- Open
terms.xml
- I recommend to verify that all terms are included
- On the second line, edit the
TermGroup
attributes:- Set
SiteCollectionTermGroup
to"false"
- Change the
Name
to something more suitable
- Set
- Do a find and replace to change SourceTermId into ID:
- Find
ID="00000000-0000-0000-0000-000000000000"
and remove all instances - Find all
SourceTermId
and replace withID
- Find
- Save the file
- Now delete the original term set in SharePoint(!)
- Apply the template to re-create the term group in the new location:
Import-PnPTermGroupFromXml -Path "C:\Temp\terms.xml"
Finally, on the original site, edit all site fields that were using the affected term sets. They will have lost their connection to the original term sets, so you need to set it again, pointing on the new one!