SharePoint Online: Create New Group in Term Store using PowerShell

Requirement: Create new group in SharePoint Online Term Store.

How to Create a New Term Group in SharePoint Online?
To create a new group in SharePoint online term store, follow these steps:
  • Navigate to your SharePoint admin center site. (E.g.
  • Click the "term store" link on the left navigation menu.
  • Click on the little arrow in the Taxonomy Header >> Click on New Group Menu option
    powershell to add new group in sharepoint online term store
  • Type the name of your term group. Hit enter to complete creating the term group.
    create term group in sharepoint online using powershell

PowerShell to Add New Term Group 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 = ""
$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
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    #Check if the given group exists already
    $TermGroups = $TermStore.Groups
    $Group = $TermGroups | Where-Object {$_.Name -eq $TermGroup}
    If(-not $Group)
        #Create Term Group
        $NewGroup = $TermStore.CreateGroup($TermGroup, [System.Guid]::NewGuid().toString())
        Write-host "Term Group '$TermGroup' Created Successfully!" -ForegroundColor Green
        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
#Config Variables
$AdminCenterURL = ""
$TermGroupName = "Regions"
$TermGroupDescription ="Term Group for Deals Pipeline Regions"

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

#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!"
    Write-host -f Yellow "Term Group '$TermGroupName' already exists!"

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.