Export SharePoint Term Set to CSV

Photo by PDPics on Pixabay

This is one of the most used features of SharePoint and sometimes, we may create this term set on a testing site and we need to transfer this term set to other sites. I’ve created a PowerShell script that allows you to export this to a CSV file. You can then use SharePoint OOTB functionality to import the term set to your taxonomy somewhere else.

This script needs to be adjusted with your credentials, the site where the term store is located in the case is configured to one site. Then select the TermStore Group and TermSet that you want to extract to the CSV. This code will is ready to get 2 levels of Term sets. If you have more levels, you need to adjust this code to get more items.

The Term store group used on this script is the People and the term set that we want to export is Department below image with the sample.

$userName = 'contoso'
$password = 'pw' | ConvertTo-SecureString -Force -AsPlainText
$cred = New-Object -typename System.Management.Automation.PSCredential($userName, $password)
$siteCollectionUrl = "https://contoso.sharepoint.com/sites/site"
[System.Collections.ArrayList] $completeTerm = [System.Collections.ArrayList]::new()

$termGroup = "People"
$termSet = "Department"

Connect-PnPOnline $siteCollectionUrl -Credentials $cred 
$termStores = Get-PnPTerm -TermGroup $termGroup -TermSet $termSet -IncludeChildTerms 
$completeTerm = @()

foreach ($termStore in $termStores) {
 $completeTerm += New-Object PsObject -Property @{
  "Term Set Name" = $termSet;
  "Level 1 Term"  = $termStore.Name;
 if ($termStore.TermsCount -gt 0) {
  foreach ($termStoreChild in $termStore.Terms) {
   $completeTerm += New-Object PsObject -Property @{ 
    "Term Set Name" = $termSet;
    "Level 1 Term"  = $termStore.Name;
    "Level 2 Term"  = $termStoreChild.Name;
$completeTerm | Select-Object "Term Set Name", "Term Set Description", "LCID", "Available for Tagging", "Term Description", "Level 1 Term", "Level 2 Term", "Level 3 Term", "Level 4 Term" | Export-Csv "./TermSet.csv" -NoTypeInformation


With this script is easy to export the term set on the SharePoint. It’s also possible to adjust the code to retrieve more terms. If you want to import the term store verify this article on option number 2 –


    • Jens said:


      Thanks for you top export Script 🙂
      i receive an error :

      [System.Collections.ArrayList] $completeTerm = [System.Collections.ArrayList]::new()
      Method invocation failed because [System.Collections.ArrayList] does not contain a method named ‘new’.
      At line:1 char:1
      + [System.Collections.ArrayList] $completeTerm = [System.Collections.ArrayList]::n …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : MethodNotFound

      What’s wrong?

      Thanks for your assistance

      June 22, 2021
  1. Christopher Mainland said:

    this ony works for two levels

    June 4, 2021
  2. Brett said:

    Does this work for SP2016 on-prem?
    Error message: Connect-PnPOnline : The term ‘Connect-PnPOnline’ is not recognized as the name of a cmdlet, function, script file, or operable program.

    July 28, 2021
    • Brett said:

      I kind of got around that error using this: Install-Module SharePointPnPPowerShellOnline -Scope CurrentUser

      July 28, 2021

Leave a Reply

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