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:
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.
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: 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= "https://crescent.sharepoint.com" $TermGroupName = "Sectors" $TermSetName = "Energy" $TermName="Midstream" #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() #Get the term $Term = $TermSet.Terms.GetByName($TermName) $Ctx.Load($Term) $Ctx.ExecuteQuery() #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) $Ctx.ExecuteQuery() Write-host -f Green "Default Label Set for the Term!" } Catch { write-host -f Red "Error: " $_.Exception.Message }
Hi, How can we achieve this using PnP Powershell?
ReplyDelete