kwizcom banner advertisement

SharePoint Online: How to Deprecate a Managed Metadata Term in Term Store using PowerShell?

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.  It doesn't affect all items which are already using the specific term!

How to deprecate a term in managed metadata Term Store?
Here is how to deprecate a term in SharePoint Online term store.
  • Login to SharePoint Online Admin Center and then "term store" from the left navigation.
  • Traverse to the particular term you want to deprecate. 
  • Select the term click on little down arrow, Click on the "Deprecate Term" option from the context menu.
Deprecated terms are displayed with a little red icon and its dimmed. The deprecated term cannot be used in new items.

Enable Deprecated Term (Un-Deprecate):
If you decide to re-enable deprecated term, You can simple click on "Enable" option from the context menu of the particular term.

How to Deprecate a Term in SharePoint Online Term Store using PowerShell? 
Now, Lets deprecate a term using 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
   }
SharePoint Online: How to Deprecate a Managed Metadata Term in Term Store using PowerShell? SharePoint Online: How to Deprecate a Managed Metadata Term in Term Store using PowerShell? Reviewed by Salaudeen Rajack on August 29, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.