Saturday, August 6, 2016

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
}



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...