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., https://tenant-admin.sharepoint.com)
- Expand “Content services” and click the “Term store” link on the left navigation menu. (In classic SharePoint Admin Center, click on the “Term store” link from the left navigation to open term store.) Make sure you are adding yourself to “Term Store Administrators” of the Term Store, before trying to make any changes.
- 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 the New Term Set option
- Start typing your term set. Hit the Enter button to complete creating the term set.
- That’s all! Term sets can be created in a site collection or at the 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.
PowerShell to create a Term Set in SharePoint Online:
Have you ever needed to create a term set in SharePoint Online but didn’t want to mess around with the UI? PowerShell to the rescue. 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 = "https://crescent-admin.sharepoint.com/"
$TermGroupName ="Regions"
$TermSetName="MENA"
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
$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)
#Check if the given term set exists already
$TermSets = $TermGroup.TermSets
$Ctx.Load($TermSets)
$Ctx.ExecuteQuery()
$TermSet = $TermSets | Where-Object {$_.Name -eq $TermSetName}
If(-not $TermSet)
{
#Create Term Set
$NewTermSet = $TermGroup.CreateTermSet($TermSetName,[System.Guid]::NewGuid().toString(),1033)
$Ctx.Load($NewTermSet)
$Ctx.ExecuteQuery()
Write-host "Term Set '$TermSetName' Created Successfully!" -ForegroundColor Green
}
else
{
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. This can be helpful if you need to create a large number of term sets or if you want to automate the process.
SharePoint Online: PnP PowerShell to Create Term Set
Are you looking for a way to automate the creation of term sets in SharePoint Online? Well, Here is how to create a term set in SharePoint Online using PnP PowerShell cmdlet New-PnPTermSet:
#Config Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
#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
you did this for Crescent Heights…right??