How do I export all the tags and metadata from a sharepoint site?

Bailey, Jennifer 5 Reputation points
2023-04-19T19:59:17.78+00:00

Hello,

Does anyone know how to export SharePoint taxonomy/terms/tags/metadata out of SharePoint in to an excel spreadsheet?

Microsoft 365 and Office | SharePoint | For business | Windows
{count} vote

2 answers

Sort by: Most helpful
  1. AllenXu-MSFT 24,951 Reputation points Moderator
    2023-04-20T06:54:26.3666667+00:00

    Hi @Bailey, Jennifer,

    Use below PowerShell script to Export All Terms from All Levels from the Term Store to CSV.

    #Load SharePoint CSOM Assemblies
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
        
    #Variables for Processing
    $AdminURL = "https://crescent-admin.sharepoint.com/"
    $ReportOutput="C:\Temp\TermStoreData.csv"
     
    #Function to get all child terms from a Term
    Function Get-SPOChildTerms([Microsoft.SharePoint.Client.Taxonomy.Term]$Term)
    {
        $TermsColl = @()
        $TermsColl += $Term.PathOfTerm
     
        #Get All child terms
        $ChildTerms = $Term.Terms
        $Ctx.Load($ChildTerms)
        $Ctx.ExecuteQuery()
      
        #Process all child terms
        Foreach ($ChildTerm in $ChildTerms)
        {
            Get-SPOChildTerms($ChildTerm)
        }
        Return $TermsColl
    }
     
    Try {
        #Get Credentials to connect
        $Cred = Get-Credential
      
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
      
         #Array to Hold Result - PSObjects
        $ResultCollection = @()
      
        #Get the term store
        $TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
        $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
        $Ctx.Load($TaxonomySession)
        $Ctx.Load($TermStore)
        $Ctx.ExecuteQuery()
      
        #Get all term groups  
        $TermGroups = $TermStore.Groups
        $Ctx.Load($TermGroups)
        $Ctx.ExecuteQuery()
      
        #Iterate through each term group
        Foreach($Group in $TermGroups)
        {
            #Get all Term sets in the Term group
            $TermSets = $Group.TermSets
            $Ctx.Load($TermSets)
            $Ctx.ExecuteQuery()
      
            #Iterate through each termset
            Foreach($TermSet in $TermSets)
            {
                Write-host "Getting Terms from Term Set '$($Termset.Name)' from Term Group '$($Group.Name)'" -f Yellow
                #Get all Terms from the term set
                $Terms = $TermSet.Terms
                $Ctx.Load($Terms)
                $Ctx.ExecuteQuery()
     
                #Iterate through each term
                Foreach($Term in $Terms)
                {
                    #Get the child terms of the term
                    $ChildTerms = Get-SPOChildTerms($Term)
     
                    ForEach($Child in $ChildTerms)
                    {
                        $TermData = new-object PSObject
                        $TermData | Add-member -membertype NoteProperty -name "Group" -Value $Group.Name
                        $TermData | Add-member -membertype NoteProperty -name "TermSet" -Value $Termset.Name             
                        $TermData | Add-member -membertype NoteProperty -name "Terms" -Value $Child
                        $ResultCollection += $TermData
                    }
                }
            }
        }
        $ResultCollection
        #Export Results to a CSV File
        $ResultCollection | Export-csv $ReportOutput -NoTypeInformation -Force
      
        Write-host "Term Store Data Successfully Exported!" -ForegroundColor Green  
    }
    Catch {
        write-host -f Red "Error Exporting Termstore Data!" $_.Exception.Message
    }
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

  2. AllenXu-MSFT 24,951 Reputation points Moderator
    2023-05-04T02:57:51.37+00:00

    Hi @Bailey, Jennifer,

    As per my test, this PowerShell script works perfectly on my side in this scenario. Do you have any concern on the answer? Feel free to share and we can go on discussing. I'm glad to provide further support.

    Appreciate your patience.

    Have a good day!!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.