
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.