SharePoint Online: Create New Term Set using PowerShell

Requirement: Create a New Term Set in SharePoint Online Term Store.

How to Create a New Term Set in SharePoint Online?
Term sets are a set of Terms stored in a hierarchical structure. E.g: Country > State > City. In other words, Terms are stored in term sets. Term sets in managed metadata service in SharePoint can be considered as a category or classification with a number of predefined terms that can be used as metadata in lists or libraries. Follow these steps to create a term set in SharePoint Online:
  • Navigate to your SharePoint admin center site. (E.g.
  • Click the "term store" link on the left navigation menu. In Modern SharePoint Admin Center, select Classic features, and then click on "Open" under Term store. Make sure you are adding yourself to "Term Store Administrators" of the Term Store, before trying to make any change.
  • If you don't have existing term groups created, you can click on the "Taxonomy_<id>" root node and then select "New Group" to create a new term group first.
  • From the taxonomy tree view, Select the term group in which you want to add a term set. Click on the little arrow in the Term group Header >> Click on New Term Set option
    powershell to create term set in sharepoint online
  • Start typing your term set. Hit the Enter button to complete creating the term set.
    SharePoint Online Create Term Set using PowerShell
  • That's all! Term sets can be created either in a site collection or at tenant level for the SharePoint Admin center to Make a term set available across all site collections.
Once the term set is created, You can set the properties of the term set, such as Term set Name, description, owner, etc.
To create and manage terms and term sets in the Term Store management tool, you must be a Contributor, a Group Manager, or a Term Store Administrator!

PowerShell to Create a Term Set in SharePoint Online:
Here is how to add a term set in SharePoint Online
#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"
#Variables for Processing
$AdminURL = ""
$TermGroupName ="Regions"

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
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()

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

    #Check if the given term set exists already
    $TermSets = $TermGroup.TermSets
    $TermSet = $TermSets | Where-Object {$_.Name -eq $TermSetName}
    If(-not $TermSet)
        #Create Term Set
        $NewTermSet = $TermGroup.CreateTermSet($TermSetName,[System.Guid]::NewGuid().toString(),1033)
        Write-host "Term Set '$TermSetName' Created Successfully!" -ForegroundColor Green
        Write-host "Term Set '$TermSetName' Exists Already!" -ForegroundColor Yellow
Catch {
    write-host -f Red "Error Adding Term Group!" $_.Exception.Message
This creates a new term set in the given term group of the SharePoint Online Term store.

SharePoint Online: PnP PowerShell to Create Term Set
Here is how to create a term set in SharePoint Online using PnP PowerShell
#Config Variables
$AdminCenterURL = ""

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Create new Term Set
New-PnPTermSet -Name "Region" -TermGroup "Deals Pipeline" 
This creates a new term set "Regions" in SharePoint Online!

Once the term set is ready, you can start adding terms to it: SharePoint Online: Create a Term in Term Store using Powershell

1 comment:

Please Login and comment to get your questions answered!

Powered by Blogger.