Export Term group with PnP PowerShell

Photo by freestocks on Unsplash

In my last blog post, I shared a PowerShell script that allows you to export a term set to a CSV file. This script has similar purposes but with fewer lines of code. This will extract the complete term group instead of the Term set as well. If you which, you can edit the file created and delete the unwanted term set that was created by this command.

First, you need to make sure you have the install the PNP PowerShell recent version, you can verify on the next link on how to install/update module if needed. After that, you just need to run the next script and that will create on a file on your PC. On our case, we will export the People term group from one site and then apply this on another tenant. Below is a little gif that shows this code in action.

Connect-PnPOnline https://CONTOSOA.sharepoint.com/ -UseWebLogin
$termgroup = Get-PnPTermGroup -GroupName people
$termgroup | Export-PnPTermGroupToXml -Out .\TermGroup.xml -FullTemplate

To apply this to the same another site, you just need to connect once more to the site and run the PowerShell script below. If you want to apply to the same site, it will override the term set group that you have on this extracted file with the same values which will not change anything. If inspect the XML or PNP file create and adding field manually, these fields will be added to your term set. The only thing that you need to be aware of is those ID that cannot be the same. If this is the case nothing will happen to the site but that can lead to issues in the future.

Connect-PnPOnline https://CONTOSOB.sharepoint.com/ -UseWebLogin
Apply-PnPProvisioningTemplate -Path .\TermGroup.xml

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *