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

[玩转系统] SharePoint Online:使用 PowerShell 删除术语组

作者:精品下载站 日期:2024-12-14 21:04:24 浏览:12 分类:玩电脑

SharePoint Online:使用 PowerShell 删除术语组


如何删除 SharePoint Online 术语库中的组

如果您需要删除术语库中的术语组,这非常容易,可以使用 SharePoint 管理中心或 PowerShell 来完成。请记住,删除术语组也会删除该组内的所有术语。本文将向您展示如何删除 SharePoint Online 中的术语组。

按照以下步骤删除 SharePoint Online 术语库中的术语组。

  1. 登录到您的 SharePoint 管理中心网站。 (例如,https://yourdomain-admin.sharepoint.com)>> 单击左侧导航菜单上的服务 >> 术语库链接。
  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"
  
#Variables for Processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$TermGroupName ="Deals Pipeline"

Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURL)
    $Ctx.Credentials = $Credentials

    #Get the term store
    $TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx) 
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    $Ctx.Load($TaxonomySession)
    $Ctx.Load($TermStore)
    $Ctx.ExecuteQuery()

    #Check if the given group exists
    $TermGroups = $TermStore.Groups
    $Ctx.Load($TermGroups)
    $Ctx.ExecuteQuery()
    $TermGroup = $TermGroups | Where-Object {$_.Name -eq $TermGroupName}
     
    If($TermGroup -ne $NULL)
    {
        #Delete all Term sets in the Term group
        $TermSets = $TermGroup.TermSets
        $Ctx.Load($TermSets)
        $Ctx.ExecuteQuery()

        $TermSets | Foreach-object {
            $_.DeleteObject()
            $Ctx.ExecuteQuery()
        }
        $TermStore.CommitAll()

        #Delete the Term Group
        $TermGroup.DeleteObject()
        $Ctx.ExecuteQuery()
     
        Write-host "Term Group '$TermGroupName' Deleted Successfully!" -ForegroundColor Green
    }
    else
    {
        Write-host "Term Group '$TermGroupName' Doesn't Exist!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Deleting Term Group!" $_.Exception.Message
}

如果您想删除一组不再需要的术语,这会很有用。

PnP PowerShell 在 SharePoint Online 中删除术语组:

使用 PnP PowerShell cmdlet Remove-PnPTaxonomyItem 删除 SharePoint Online 中不需要的术语组。


#Config Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"

#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Interactive

#Delete the Term Group "Geography"
Remove-PnPTaxonomyItem "Geography" -Force

此 PowerShell 脚本删除组“Geography”及其所有子组。

[玩转系统] SharePoint Online:使用 PowerShell 删除术语组

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

取消回复欢迎 发表评论:

关灯