0

How can I delete all Enterprise Keywords in our Sharepoint Online. It seems that the Term Store is already populated with many, many entries.

Is there a way to "reset" or delete all Enterprise keywords?

In GUI, I can't find a "Delete ALL"-Button. How about powershell? Does some have a script?

0

How to delete Enterprise Keywords using SharePoint CSOM in PowerShell

Clear-Keywords.ps1 PS script:

param (
     [string]$UserName,
     [string]$Password,
     [string]$Url
 )

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Taxonomy")



Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}


Function Clear-Keywords([Microsoft.SharePoint.Client.ClientContext]$Context)
{
    $taxSession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Context)
    $termStore = $taxSession.GetDefaultKeywordsTermStore()
    $keywords = $termStore.KeywordsTermSet.Terms
    $Context.Load($keywords)
    $Context.ExecuteQuery()

    $keywords | % { $_.DeleteObject() }
    $Context.ExecuteQuery()
}


$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password
Clear-Keywords -Context $context
$context.Dispose()

Usage

.\Clear-Keywords.ps1 -Url "https://contoso.sharepoint.com/" -UserName "username@contoso.onmicrosoft.com" -Password "password"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.