SharePoint Online: Get All Terms from a Term Set using Powershell
Requirement: PowerShell to Get All Terms from a Term Set in SharePoint Online
SharePoint Online: Get Terms from a Term Set using PowerShell
PnP PowerShell to Get All Terms from a Term Set in SharePoint Online:
The Get-PnPTerm also supports -IncludeChildTerms -Recursive parameters!
SharePoint Online: Get Terms from a Term Set using PowerShell
#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" #Function to recursively get all child terms from a Term Function Get-SPOTerm([Microsoft.SharePoint.Client.Taxonomy.Term]$Term) { Write-host $Term.Name #Get All child terms $ChildTerms = $Term.Terms $Ctx.Load($ChildTerms) $Ctx.ExecuteQuery() #Process all child terms Foreach ($ChildTerm in $ChildTerms) { $Indent = $Indent +"`t" Write-host $Indent -NoNewline Get-SPOTerm($ChildTerm) } $Indent = "`t" } #Parameters $AdminCenterURL = "https://crescenttech-admin.sharepoint.com" $TermGroupName="Deals Pipeline" $TermsetName="Dealstage" #Get Credentials to connect $Cred= Get-Credential #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminCenterURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password) #Get the taxonomy session and termstore $TaxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx) $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore() $Ctx.Load($TaxonomySession) $Ctx.Load($TermStore) #Get the Term Group $TermGroup = $TermStore.Groups.GetByName($TermGroupName) $Ctx.Load($TermGroup) #Get the termset $TermSet = $TermGroup.TermSets.GetByName($TermSetName) $Ctx.Load($TermSet) $Ctx.ExecuteQuery() #Get all terms $TermColl=$TermSet.Terms $Ctx.Load($TermColl) $Ctx.ExecuteQuery() # Loop through all the terms Foreach($Term in $TermColl) { #Get the terms recursively Get-SPOTerm($Term) }
PnP PowerShell to Get All Terms from a Term Set in SharePoint Online:
#Config Variables $AdminCenterURL = "https://crescenttech-admin.sharepoint.com" #Connect to PnP Online Connect-PnPOnline -Url $AdminCenterURL -Credentials (Get-Credential) #Get All Terms from a Term Set Get-PnPTerm -TermSet "DealStage" -TermGroup "Deals Pipeline"result:
The Get-PnPTerm also supports -IncludeChildTerms -Recursive parameters!
It is actually heplful. THank you for publishing such information.
ReplyDeleteCan you also help me with my requirement?
I want to fetch the details as in what terms have been assigned to what users.
example:- we have used Location and created India, US, UK etc... which is now populating in front of Office Location under user profiles.
Any help is appreciated
You can export user profile properties using PowerShell: How to Export User Profile Properties in SharePoint Online using PowerShell
Delete