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

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

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

SharePoint Online:如何使用 PowerShell 删除术语?


要求:从 SharePoint Online 术语库中删除术语。

如何使用 PowerShell 删除 SharePoint Online 中的术语?

如果您想清理术语库并确保所有术语都井井有条并正确分类,则删除术语至关重要。这篇博文将向您展示如何删除 SharePoint Online 中的术语。请注意,如果您删除某个术语,则之前用已删除术语标记的项目将不再用该术语标记!删除术语会删除该术语的所有实例。

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

  1. 导航到您的 SharePoint Online 管理中心网站。 (例如,https://-admin.sharepoint.com)
  2. 展开“内容服务”,然后单击左侧导航菜单上的“术语存储”链接。
  3. 从分类树视图中,展开术语组、术语集,一直展开到要删除的术语。
  4. 单击术语标题中的三个小点>>选择“删除术语”选项。确认从 SharePoint Online 术语存储中删除术语的提示。

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

用于从 SharePoint Online 术语库中删除术语的 PowerShell:

作为 SharePoint Online 管理员,您可能需要从术语库中删除术语。本文将向您展示如何使用 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 ="Regions"
$TermSetName ="MENA"
$TermName ="UAE"

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()

    #Get the Term Group
    $TermGroup=$TermStore.Groups.GetByName($TermGroupName)

    #Get the term set
    $TermSet = $TermGroup.TermSets.GetByName($TermSetName)

    #Get the term
    $Term = $TermSet.Terms.GetByName($TermName)

    #Delete the term
    $Term.DeleteObject()
    $Ctx.ExecuteQuery()
     
    Write-host "Term '$TermName' Deleted Successfully!" -ForegroundColor Green
}
Catch {
    write-host -f Red "Error Deleting Term!" $_.Exception.Message
}

请注意,此删除操作不可逆!如果删除某个术语,则在编辑具有该术语的任何现有文档/项目时,必须使用不同的术语重新标记它们。因此,您可以“弃用”该术语,使其隐藏,而不是删除。或者,您可以配置任何术语的“可用于标记”属性,使其不可用于标记。

PowerShell 从术语集中删除所有术语:

让我们从 SharePoint Online 的特定术语集中删除所有术语。


#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 ="Regions"
$TermSetName ="MENA"
 
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()
 
    #Get the term group    
    $TermGroups = $TermStore.Groups
    $Ctx.Load($TermGroups)
    $Ctx.ExecuteQuery()
    $TermGroup = $TermGroups | Where-Object {$_.Name -eq $TermGroupName}
      
    If($TermGroup -ne $NULL)
    {
         #Get the Term set
        $TermSets = $TermGroup.TermSets
        $Ctx.Load($TermSets)
        $Ctx.ExecuteQuery()
        $TermSet = $TermSets | Where-Object {$_.Name -eq $TermSetName}
     
        If($TermSet -ne $NULL)
        {
            #Delete all Terms from the Term Set
            $Terms = $TermSet.Terms
            $Ctx.Load($Terms)
            $Ctx.ExecuteQuery()
 
            #Delete all Terms from the Term Set
            $Terms | Foreach-object {
            $_.DeleteObject()
            $Ctx.ExecuteQuery()
            }
     
            Write-host "All Terms Deleted Successfully from the Term Set '$TermSetName'!" -ForegroundColor Green
        }
        else
        {
            Write-host "Term Set '$TermSetName' Exists Already!" -ForegroundColor Yellow
        }
    }
    else
    {
        Write-host "Term Group '$TermGroupName' doesn't Exist!" -ForegroundColor Yellow
    } 
}
Catch {
    write-host -f Red "Error Deleting All Terms from the Termset !" $_.Exception.Message
}

SharePoint Online:使用 PnP PowerShell 删除术语

让我向您展示如何使用 PnP PowerShell cmdlet Remove-PnPTaxonomyItem 删除术语:


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

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

#Delete the Term "South America" from Term set "regions" under "Deals Pipeline" Group
Remove-PnPTaxonomyItem "Deals Pipeline|Regions|South America" -Force
  • SharePoint Online:使用 PowerShell 删除术语组
  • SharePoint Online:使用 PowerShell 创建新术语集
  • SharePoint Online:使用 PowerShell 删除术语集
  • SharePoint Online:如何从 CSV 文件导入术语集?

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

取消回复欢迎 发表评论:

关灯