SharePoint Online: Update Term Set Name, Description, Tagging Options using PowerShell
Requirement: Set Term Set Name, Description, Tagging Options using PowerShell in SharePoint Online.
SharePoint Online: Set Term Set Name, Description, Tagging Options using PowerShell
In this blog post, we will be looking at how you can use PowerShell to update a Term Set in SharePoint Online. This can come in handy if you need to change a Term Set through scripting instead of the standard browser interface.
Here is how to update a term set in SharePoint Online 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"
#Set Variables
$SiteURL= "https://crescent.sharepoint.com"
$TermGroupName = "Sectors"
$TermSetName = "Energy"
$TermSetNewName = "Energy Sector"
$TermSetDescription = "Term Set for Energy Apps"
$AvailableForTagging = $False
#Setup Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the Taxonomy Session and Term Store
$TaxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
$TaxonomySession.UpdateCache()
$Ctx.Load($TaxonomySession)
$TermStore = $TaxonomySession.GetDefaultSiteCollectionTermStore()
$Ctx.Load($TermStore)
$Ctx.ExecuteQuery()
#Get the Term Group
$TermGroup = $TermStore.Groups.GetByName($TermGroupName)
$Ctx.Load($TermGroup)
#Get the Term Set
$TermSet = $TermGroup.TermSets.GetByName($TermSetName)
$Ctx.Load($TermSet)
$Ctx.ExecuteQuery()
#Set Term Set Name, description, Available For Tagging options
$Termset.Name = $TermSetNewName
$TermSet.Description = $TermSetDescription
$TermSet.IsAvailableForTagging = $AvailableForTagging
$Ctx.ExecuteQuery()
Write-host -f Green "Term Set Settings Updated Successfully!"
}
Catch {
write-host -f Red "Error: " $_.Exception.Message
}
PnP PowerShell to Update Term Set in SharePoint Online
PnP PowerShell makes it much simpler!
#Parameters
$AdminCenterURL = "https://crescent-admin.sharepoint.com"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Update Term Set
Set-PnPTermSet -Identity "Top Navigation" -TermGroup "Global Top Navigation" -IsAvailableForTagging $True -UseForSiteNavigation $True