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?
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 useful way to track the business owners or stakeholders for a term set. To set a Owner for Term set in SharePoint Online, do the following:
  • Login to SharePoint Online Admin Center >> Click on "term store" link from left navigation
  • Traverse through the tree view and pick the term set and enter the "Owner" field. 
  • Click on save to commit your changes.term set owner sharepoint online
SharePoint Online: PowerShell to Set Term Set Owner
#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
}
SharePoint Online: Change Term Set Owner using PowerShell SharePoint Online: Change Term Set Owner using PowerShell Reviewed by Salaudeen Rajack on July 08, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.