Apply term sets as Global Navigation in SharePoint site using PowerShell and CSOM

InfoPath alternatives for form designing SharePoint

In this post I am going to explain how to apply term-sets as Global Navigation in SharePoint site using PowerShell and CSOM. In my previous post I have explained how to create term sets using PowerShell and CSOM.

Now below script has details how to apply the term-sets as Global Navigation in SharePoint Site.

Also check out:
– Search People as a Search Scope or Content Source Using SharePoint 2013 REST API

– Create an event handler to prevent items from deleting item from SharePoint list using Visual Studio 2010

– Design Manager in SharePoint 2013 designer

Below is the Script Code:


$0 = $MyInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
$xmlFilePath = $(“$dp0\Inputs.xml”)
$xmldata = [xml](Get-Content($xmlFilePath));

$username = “”
$password = Read-Host -Prompt “Please enter your password” -AsSecureString

$url = $xmldata.WebSite.Url

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials

Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.dll”
Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.Runtime.dll”
Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.Publishing.dll”
Add-Type -Path “C:\Lib\Microsoft.SharePoint.Client.Taxonomy.dll”

if (!$clientContext.ServerObjectIsNull.Value)
Write-Host “Connected to SharePoint Online site: ‘$Url'” -ForegroundColor Green

$web = $clientContext.Web

function UpdateTopNavWebProperty([Microsoft.SharePoint.Client.Web] $web)

Write-Host “set global navigation settings to Managed Metadata started” -ForegroundColor Green
$taxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($clientContext)
$termStores = $taxonomySession.TermStores

try {

$termStore = $termStores[0]
$Groups = $termStore.Groups


#Get Site collection Group
foreach($Group in $Groups)
foreach($solenisTermSet in $solenisTermSets)

Write-Host “Error detail ” $_.Exception.Message -foregroundcolor black -backgroundcolor Red
$fId = [GUID]$TermID

$navigationSettings = New-Object Microsoft.SharePoint.Client.Publishing.Navigation.WebNavigationSettings $clientContext, $clientContext.Web

#For Display the same navigation items as the parent site
$navigationSettings.GlobalNavigation.Source = “taxonomyProvider”
$navigationSettings.GlobalNavigation.TermStoreId = $termStore.Id
$navigationSettings.GlobalNavigation.TermSetId = $fId

try {
Write-Host “setting global navigation settings to Managed Metadata Completed” -foregroundcolor black -backgroundcolor green
Write-Host “Error while setting global navigation settings to Managed Metadata” $_.Exception.Message -foregroundcolor black -backgroundcolor Red

UpdateTopNavWebProperty $web

Xml Inputs –

<?xml version=”1.0″ encoding=”utf-8″?>
<WebSite Url=”” >
<TermMain TermName=”Custom Top Navigation” GroupURL=”” >
<TermSet Name=”Home” Url=”/” Order=”1″>
<TermSet Name=”Departments” Url=”/sites/Library” Order=”2″>
<Term Name=”Accounting” Url=”/sites/Accounting”>
<TermSub Name=”Accounting1″ Url=”/sites/Accounting/Accounting1″ />
<Term Name=”IT” Url=”/sites/IT” />
<Term Name=”Marketing” Url=”/sites/Marketing” />


Similar SharePoint 2013 Tutorials

About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →

Leave a Reply