SharePoint Online: Change Term Set Owner using PowerShell
Requirement: Change Term Set Owner in SharePoint Online.
How to Configure Term Set Owner in SharePoint Online?
In SharePoint Online, a term set owner is a user or a group of users responsible for managing the terms in a term set. When you create a term set, you can designate a group or a person as a Term Set Owner. Setting Term set owner doesn’t give any permission to it, but it provides a helpful way to track the business owners or stakeholders for a term set.
To set an Owner for Term set in SharePoint Online, do the following:
- Login to SharePoint Online Admin Center >> Click on the “Term store” link under “Content services” from the left navigation.
- Traverse through the tree view and pick the term set and click on “Edit” link to set the “Owner”.
- Enter the owner for the term set and click on save to commit your changes.
SharePoint Online: PowerShell to Set Term Set Owner
Use this PowerShell to update the owner of a Term set:
#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"
$TermSetOwner= "i:0#.f|membership|Salaudeen@Crescent.com"
#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 termset
$TermSet = $TermGroup.TermSets.GetByName($TermSetName)
$Ctx.Load($TermSet)
$Ctx.ExecuteQuery()
#Set Term Set Owner
$TermSet.Owner = $TermSetOwner
$TermStore.CommitAll()
$Ctx.ExecuteQuery()
Write-host -f Green "Term Set Owner has been Updated!"
}
Catch {
write-host -f Red "Error: " $_.Exception.Message
}
Similarly, we can set term set owner for all term sets in the tenant as:
#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"
$TermSetOwner= "i:0#.f|membership|Salaudeen@Crescent.com"
#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 All Term Groups
$TermGroups = $TermStore.Groups
$Ctx.Load($TermGroups)
$Ctx.ExecuteQuery()
ForEach($TermGroup in $TermGroups)
{
#Get the termset
$TermSets = $TermGroup.TermSets
$Ctx.Load($TermSets)
$Ctx.ExecuteQuery()
ForEach($TermSet in $TermSets | Where {$_.Name -ne "Orphaned Terms"})
{
#Set Term Set Owner
$TermSet.Owner = $TermSetOwner
}
}
$TermStore.CommitAll()
$Ctx.ExecuteQuery()
Write-host -f Green "Term Set Owner has been Updated for All Term Sets!"
}
Catch {
write-host -f Red "Error: " $_.Exception.Message
}
PnP PowerShell to Update Term Set Owner in SharePoint Online
Here is the PnP PowerShell method to set the owner of a term set:
#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" -Owner Steve@crescent.com