当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 更改术语集所有者

作者:精品下载站 日期:2024-12-14 15:05:01 浏览:15 分类:玩电脑

SharePoint Online:使用 PowerShell 更改术语集所有者


要求:更改 SharePoint Online 中的术语集所有者。

如何在 SharePoint Online 中配置术语集所有者?

在 SharePoint Online 中,术语集所有者是负责管理术语集中的术语的用户或一组用户。创建术语集时,您可以指定一个组或个人作为术语集所有者。设置术语集所有者并不授予任何权限,但它提供了一种有用的方法来跟踪术语集的业务所有者或利益相关者。

要在 SharePoint Online 中设置术语集的所有者,请执行以下操作:

  1. 登录 SharePoint Online 管理中心 >> 单击左侧导航中“内容服务”下的“术语存储”链接。
  2. 遍历树视图并选择术语集,然后单击“编辑”链接以设置“所有者”。

    [玩转系统] SharePoint Online:使用 PowerShell 更改术语集所有者

  3. 输入术语集的所有者,然后单击“保存”以提交更改。

    [玩转系统] SharePoint Online:使用 PowerShell 更改术语集所有者

SharePoint Online:PowerShell 设置术语集所有者

使用此 PowerShell 更新术语集的所有者:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
   
#Set Variables
$SiteURL= "https://crescent.sharepoint.com"
$TermGroupName = "Sectors"
$TermSetName= "Energy"
$TermSetOwner= "i:0#.f|membership|[email protected]"

#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
}

同样,我们可以将租户中所有术语集的术语集所有者设置为:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
   
#Set Variables
$SiteURL= "https://crescent.sharepoint.com"
$TermSetOwner= "i:0#.f|membership|[email protected]"

#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 更新 SharePoint Online 中的术语集所有者

以下是设置术语集所有者的 PnP PowerShell 方法:


#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 [email protected]

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯