kwizcom banner advertisement

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. https://yourdomain-admin.sharepoint.com)
  • 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 = "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
#Config Variables
$AdminCenterURL = "https://crescenttech-admin.sharepoint.com"
$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!"
}
Else
{
    Write-host -f Yellow "Term Group '$TermGroupName' already exists!"
}
SharePoint Online: Create New Group in Term Store using PowerShell SharePoint Online: Create New Group in Term Store using PowerShell Reviewed by Salaudeen Rajack on August 06, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.