SharePoint Online: How to Update Term Labels in Term Store using PowerShell?

Requirement: Update Term Label in SharePoint Online using PowerShell

How to Set Default Label and Other Label for a Managed Metadata Term in SharePoint Online?
To update labels for a term in SharePoint Online,  do the following:
  • Login to SharePoint Online Admin Center >> Click on "term store" link from the left navigation.
  • Expand term groups, Term Sets and pick the target term to set term label.
  • Default term label and other labels can be set for the term as in below screen.
  • Hit save to commit your changes.sharepoint online powershell update term label

SharePoint Online: Update Default Term Label using PowerShell:
This PowerShell script updates the default label for a given term and adds "Other Labels" for the term.
#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= ""
$TermGroupName = "Sectors"
$TermSetName = "Energy"

#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)
    $TermStore = $TaxonomySession.GetDefaultSiteCollectionTermStore()

    #Get the Term Group    
    $TermGroup = $TermStore.Groups.GetByName($TermGroupName)

    #Get the Term Set
    $TermSet = $TermGroup.TermSets.GetByName($TermSetName)

    #Get the term
    $Term = $TermSet.Terms.GetByName($TermName)

    #Update Default Label of the Term
    $DefaultTermLabel = $Term.CreateLabel("Midstream V2", 1033, $True)

    #Add Other Labels
    $OtherTermLabel = $Term.CreateLabel("Midstream V3", 1033, $False)
    $OtherTermLabel = $Term.CreateLabel("Midstream V4", 1033, $False)

    Write-host -f Green "Default Label Set for the Term!"
Catch {
    write-host -f Red "Error: " $_.Exception.Message

1 comment:

  1. Hi, How can we achieve this using PnP Powershell?


Please Login and comment to get your questions answered!

Powered by Blogger.