SharePoint Online: How to Deprecate a Managed Metadata Term in Term Store using PowerShell?
The Managed Metadata Term Store in SharePoint Online provides a fantastic way to classify data and enhance search results using pre-defined Terms. However, there are situations where you may need to remove terms from use. So, If you decide to retire a term – Don’t delete them, but deprecate them instead. Deprecating a Term prevents the term from being used any further, and it doesn’t affect all items which are already using the specific term! Follow these steps when you decide to deprecate a term that is no longer being used or should not be used in the future!
How to deprecate a term in managed metadata Term Store?
Here is how to deprecate a term in the SharePoint Online term store:
- Login to SharePoint Online Admin Center >> Expand “Content Services” and then click on “Term store” from the left navigation.
- Traverse to the particular term you want to deprecate.
- Select the term click on the little down arrow, click on the “Deprecate Term” option from the context menu (or from the toolbar!).
Deprecated terms are displayed with a little red icon and dimmed, and the deprecated term cannot be used in new items.
Enable Deprecated Term (Un-Deprecate):
If you decide to re-enable a deprecated term, You can simply click on the “Enable Term” option from the context menu of the particular term.
How to Deprecate a Term in SharePoint Online Term Store using PowerShell?
Now, let’s deprecate a term using the CSOM-PowerShell script.
#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 parameter values
$SiteURL="https://crescent.sharepoint.com/"
#Termset parameters
$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($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Taxonomy Session
$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)
$Ctx.Load($TermGroup)
#Get the termset
$TermSet = $TermGroup.TermSets.GetByName($TermSetName)
$Ctx.Load($TermSet)
#Get the term
$Term = $TermSet.Terms.GetByName($TermName)
$Ctx.Load($Term)
$Ctx.ExecuteQuery()
#Deprecate the Term
$Term.Deprecate($True) #$False - Enables the Term back
$Ctx.ExecuteQuery()
Write-host -f Green "Term has been Deprecated successfully!"
}
Catch {
write-host -f Red "Error Deprecating Term!" $_.Exception.Message
}
PnP PowerShell to Deprecate a Term in SharePoint Online
We can also deprecate a term with PnP PowerShell:
#Parameters
$AdminCenterURL = "https://Crescent-Admin.sharepoint.com"
$TermName = "DevOps Engineer"
$TermSetName = "Job Titles"
$TermGroupName = "Deals Pipeline"
#Deprecate a Term
Set-PnPTerm -Identity $TermName -TermSet $TermSetName -TermGroup $TermGroupName -Deprecated $true