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?

Term sets in managed metadata service in SharePoint can be considered as a category or classification with number of predefined terms that can be used as metadata in lists or libraries.
Follow these steps to create a term set in SharePoint Online:

  • 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"

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()

    #Get the Term Group    
    $TermGroup = $TermStore.Groups.GetByName($TermGroupName)

    #Check if the given term set exists already
    $TermSets = $TermGroup.TermSets
    $TermSet = $TermSets | Where-Object {$_.Name -eq $TermSetName}
    If(-not $TermSet)
        #Create Term Set
        $NewTermSet = $TermGroup.CreateTermSet($TermSetName,[System.Guid]::NewGuid().toString(),1033)
        Write-host "Term Set '$TermSetName' Created Successfully!" -ForegroundColor Green
        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.

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