Yesterday I publish an article how to replace/add keywords on documents. But one of the requirements was that you needed the ID of the term you want to find and add/replace. So yet again I created a small function that allows you to return all terms from the store.
You still need the PnP SharePoint cmdlets, which you can download here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
Function Get-SPTaxKeyword { #Object array. $TermsCollection = @(); #Get all term groups. $TermGroups = Get-PnPTermGroup; #Foreach term group. Foreach($TermGroup in $TermGroups) { #Get all term sets. $TermSets = $TermGroup | Get-PnPTermSet; #Foreach term set. Foreach($TermSet in $TermSets) { #Get all terms. $Terms = Get-PnPTerm -TermGroup $TermGroup.Name -TermSet $TermSet.Name; #Foreach term. Foreach($Term in $Terms) { #If a term is present. If($Term) { #Create a new object. $TermCollection = New-Object -TypeName PSObject; #Add value to the object. Add-Member -InputObject $TermCollection -Membertype NoteProperty -Name "TermGroupName" -Value ($TermGroup.Name); Add-Member -InputObject $TermCollection -Membertype NoteProperty -Name "TermGroupId" -Value ($TermGroup.Id); Add-Member -InputObject $TermCollection -Membertype NoteProperty -Name "TermGroupSetName" -Value ($TermSet.Name); Add-Member -InputObject $TermCollection -Membertype NoteProperty -Name "TermGroupSetId" -Value ($TermSet.Id); Add-Member -InputObject $TermCollection -Membertype NoteProperty -Name "TermName" -Value ($Term.Name); Add-Member -InputObject $TermCollection -Membertype NoteProperty -Name "TermId" -Value ($Term.Id); #Add to the object array. $TermsCollection += $TermCollection; } } } } #Return terms. Return $TermsCollection; } #Get all keywords. $Keywords = Get-SPTaxKeyword; |