Managed metadata navigation settings in SharePoint 2013 using Powershell

In a different blog post I have explained the basics of working with publishing navigation in SharePoint 2013. The OOB navigation offers two options: “structural navigation” and “managed metadata navigation”.

Managed metadata navigation is bound to a term set, that provides the navigation nodes for your site (more details on how to configure it here). If you want to change this, or you are simply looking for a script that will set this up in new environments, here it is:

Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$assembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")

function UpdateNavigation($url,$termStoreName,$termGroupName,$termSetName){
 $web= Get-SPWeb $url
 $site = $web.Site
 $navSettings = New-Object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings($web)
 $taxSession = Get-SPTaxonomySession -Site $site
 $termStore = $taxSession.TermStores[$termStoreName]
 $termGroup = $termStore.Groups[$termGroupName]
 $termSet = $termGroup.TermSets[$termSetName]
 #Quick Launch
 $navSettings.CurrentNavigation.Source = 2
 $navSettings.CurrentNavigation.TermStoreId = $termStore.Id
 $navSettings.CurrentNavigation.TermSetId = $termSet.Id
 #Global Navigation
 $navSettings.GlobalNavigation.Source = 2
 $navSettings.GlobalNavigation.TermStoreId = $termStore.Id
 $navSettings.GlobalNavigation.TermSetId = $termSet.Id

$navSettings.AddNewPagesToNavigation = $false
 $navSettings.CreateFriendlyUrlsForNewPages = $false
 $navSettings.Update()
 Write-Host "Navigation updated succesfully for site $url"
}
#Sample usage: UpdateNavigation http://spdevel.portal.com/ "Managed Metadata Service" "My Navigation Group" "Navigation"

An important limitation of this managed metadata navigation is the fact that a term set can only be bound to a single site. You can find more on this topicĀ post.

About these ads
3 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: