O365 - Update Managed Metadata Term Set Description using CSOM in PowerShell

Perhaps not the most sophisticated of scripts but, a valuable one nonetheless.

The example PowerShell script below can be used to configure the value of the “Description” property of Term Sets in SharePoint Online.

It requires five variables to be updated - $User which is the tenant admin, $TenantURL which is the URL for the SharePoint Admin Center, $Site which is a valid URL of any SharePoint Site Collection that exists within the tenant, $GroupName which is the name of the Term Group you wish to connect to and $TermSetName which is the name of the Term Set for which you wish to configure the value of the description property.

$User = "<Tenant Admin>"

$TenantURL = "<URL of SharePoint Admin Center>"

$Site = "<URL of Site Collection that exists in the tenant>"

$GroupName = "<Term Group Name that contains the target Term Set>"

$TermSetName = "<Target Term Set Name>"

 

#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM

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"

$Password = Read-Host -Prompt "Please enter your password" -AsSecureString

try

{

 

#Bind to the Managed Metadata Service within the target instance of SPO

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)

$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)

$Context.Credentials = $Creds

$MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Context)

$Context.Load($MMS)

$Context.ExecuteQuery()

 

#Retrieve all of the Term Stores from the Managed Metadata Service

$TermStores = $MMS.TermStores

$Context.Load($TermStores)

$Context.ExecuteQuery()

 

#Bind to the Term Store you want to perform configurations against

$TermStore = $TermStores[0]

$Context.Load($TermStore)

$Context.ExecuteQuery()

 

#Bind to the Term Group you want to perform configurations against

$Group = $TermStore.Groups.GetByName($GroupName)

$Context.Load($Group)

$Context.ExecuteQuery()

 

#Bind to Term Set you want to perform configurations against

$TermSet = $Group.TermSets.GetByName($TermSetName)

$Context.Load($TermSet)

$Context.ExecuteQuery()

 

 

# Update term set description

$TermSet.Description = "This Term set description has just been updated"

$context.ExecuteQuery()

 

}

 

catch

{

    write-host "Caught an exception:" -ForegroundColor Red

    write-host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red

    write-host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red

}

finally

{

    write-host ""

    write-host "The description of the Term Set has been successfully updated!" -ForegroundColor Green

}