SharePoint Online: Create a New Group in Term Store using PowerShell
Requirement: Create a new group in SharePoint Online Term Store.
How to Create a New Term Group in SharePoint Online?
Have you ever needed to create a new group in the Term Store for SharePoint Online? In this post, we will walk through the steps necessary to create a new group in the Term Store using the SharePoint Admin center. We will also provide some script scripts that you can use as a starting point for creating your term groups in SharePoint Online.
To create a new group in the SharePoint Online term store, follow these steps:
- Navigate to your SharePoint admin center site. (E.g., https://yourdomain-admin.sharepoint.com)
- Expand “Content services” and click the “Term store” link on the left navigation menu.
- Click on the little three vertical dots in the “Taxonomy” Header >> Click on “New Term Group” from the Menu option.
- Type the name of your term group. Hit enter to complete creating the term group.
Once you have created the new group, you can add term sets to it.
PowerShell to Add New Term Group in SharePoint Online:
If you’re like most administrators, you’ll want to automate the process of creating new groups in your Term Store. Let me show you how to do that with PowerShell.
#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/"
$TermGroup ="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
$TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
$TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
$Ctx.Load($TaxonomySession)
$Ctx.Load($TermStore)
$Ctx.ExecuteQuery()
#Check if the given group exists already
$TermGroups = $TermStore.Groups
$Ctx.Load($TermGroups)
$Ctx.ExecuteQuery()
$Group = $TermGroups | Where-Object {$_.Name -eq $TermGroup}
If(-not $Group)
{
#Create Term Group
$NewGroup = $TermStore.CreateGroup($TermGroup, [System.Guid]::NewGuid().toString())
$Ctx.Load($NewGroup)
$Ctx.ExecuteQuery()
Write-host "Term Group '$TermGroup' Created Successfully!" -ForegroundColor Green
}
else
{
Write-host "Term Group '$TermGroup' Exists Already!" -ForegroundColor Yellow
}
}
Catch {
write-host -f Red "Error Adding Term Group!" $_.Exception.Message
}
Create Term Group in SharePoint Online using PnP PowerShell
In SharePoint Online, the term store provides a way to manage taxonomy and metadata across multiple sites and site collections. Creating a new group in the term store can help organize and manage term sets and terms. Let’s see how to use PnP PowerShell to create a new group in the Term Store:
#Config Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$TermGroupName = "Regions"
$TermGroupDescription ="Term Group for Deals Pipeline Regions"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Check if Term group exists
If(-Not(Get-PnPTermGroup -Identity $TermGroupName -ErrorAction SilentlyContinue))
{
#Create new group in Termstore
New-PnPTermGroup -Name $TermGroupName -Description $TermGroupDescription
Write-host -f Green "Term Group '$TermGroupName' created successfully!"
}
Else
{
Write-host -f Yellow "Term Group '$TermGroupName' already exists!"
}
In summary, The term store can be a useful tool for managing taxonomy and metadata for SharePoint Online tenants. Creating a new group in the term store in SharePoint Online is a simple process that can be done in a few easy steps. Following the steps outlined in this article, you can easily create a new group in the term store and start organizing term sets and terms.