Export and Import Site Collection Term Groups using PnP PowerShell
Managed metadata allows the creation of central managed term sets that can be used as attributes in SharePoint sites, term sets can be created globally and shared across site collections or can be created locally to the site collection.
The PnP PowerShell includes commands to export and import terms groups but unfortunately the site collection term group is not exported automatically, this article provides a workaround to get all the site collection term sets into an xml ready to import into other site collections.
Export the Site collection term group
If you try to export just the site collection term group using the name or the GUID you will end up with an empty xml file, to avoid this scenario you will have to extract the entire taxonomy.
To do it execute the script bellow, adjust the file path and site collection URL variables to save the XML file.
$siteCollectionUrl = "https://contoso.sharepoint.com/" $filePath = "c:\path\to\file\siteCollectionTermGroup.xml" Connect-PnPOnline -Url $siteCollectionUrl -UseWebLogin Export-PnPTermGroupToXml -Out $filePath -Identity "00000000-0000-0000-0000-000000000000" [xml]$xml = Get-Content -Path $filePath foreach ($termGroup in $xml.TermGroups.TermGroup) { if (!$termGroup.Name.Equals("{sitecollectiontermgroupname}")) { $xml.TermGroups.RemoveChild($termGroup) } } $xml.save($filePath)
Import the Site collection term group
Now that you have the site collection term groups in the XML file you can import it to another site collections.
To do it execute the script bellow and adjust the file path and site collection URL variables.
$siteCollectionUrl = "https://contoso.sharepoint.com/sites/cars" $filePath = "c:\path\to\file\siteCollectionTermGroup.xml" Connect-PnPOnline -Url $siteCollectionUrl -UseWebLogin Import-PnPTermGroupFromXml -path $filePath
No comments yet