Tuesday, September 6, 2016

SharePoint Online: Create New Term Set using PowerShell

Requirement: Create New Term Set in SharePoint Online Term Store.

How to Create a New Term Set in SharePoint Online?
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.
  • 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 New Term Set option
    powershell to create term set in sharepoint online
  • Start typing your term set. Hit Enter button to complete creating the term set.
    SharePoint Online Create Term Set using PowerShell
  • That's all!

PowerShell to Create 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 new term set in the given term group of SharePoint Online Term store.



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...