Replicate term set changes for managed metadata navigations

This post is a supplement to Limitations and workarounds for managed metadata navigation for multiple site collections.

According to my last post I’ve updated the navigation for all my site collections to use a term set with pinned terms from the global navigation term set.
What I didn’t was the fact that changes in the global navigation term set won’t be applied to pinned terms in other sets.

To apply this changes I’ve written a simple PowerShell function that repins the global navigation terms on the allocated navigation term set.

$Metadata = @{
	Title = "Update SharePoint Web Term Navigation"
	Filename = "Update-SPWebTermNavigation.ps1"
	Description = ""
	Tags = "sharepoint, managed, metadata, navigation"
	Project = ""
	Author = "Janik von Rotz"
	AuthorContact = ""
	CreateDate = "2014-05-09"
	LastEditDate = "2014-05-09"
	Url = ""
	Version = "0.0.0"
	License = @'
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Switzerland License.
To view a copy of this license, visit or 
send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

function Update-SPWebTermNavigation{

    Update the term based navigation for a speific SharePoint website.

    Update the term based navigation for a speific SharePoint website.

	Url of the website.

	Managed metadata site.

.PARAMETER TermStoreName
	Name of the term store that holds the navigation term groups.

.PARAMETER TermGroupName
	Name of the term group that holds the navigation term sets.

	Name of the term set that hold the navigation terms for this website.

.PARAMETER GlobalNavigationTermGroupName
	Name of the term group that holds the global navigation term set. Only required if this is different from the term group name.

.PARAMETER GlobalNavigationTermSetName
	Name of the global term set where the terms should be pinned from.

	PS C:\> Update-SPWebTermNavigation -Identity "" -MMSSite "" -TermStoreName "Store1" -TermGroupName "Navigation" -TermSetName "SiteXY" -GlobalNavigationTermSetName "GlobalNavigation"

	PS C:\> Update-SPWebTermNavigation -Identity "" -MMSSite "" -TermStoreName "Store1" -TermGroupName "Navigation" -TermSetName "SiteXY" -GlobalNavigationTermGroupName "AnotherNavigation" -GlobalNavigationTermSetName "GlobalNavigation"






    # modules

    if(-not (Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue)){Add-PSSnapin "Microsoft.SharePoint.PowerShell"}
    # main

    Write-Host "Update term navigation settings for: $Identity"

    # get website and site collection
    $SPWeb = Get-SPWeb $Identity
    $SPSite = $SPWeb.Site

    # get the navigation settings
    $WebNavigationSettings = New-Object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings($SPWeb)

    # get the navigation term set
    $SPTaxonomySession = Get-SPTaxonomySession -Site $MMSSite
    $TermStore = $SPTaxonomySession.TermStores[$TermStoreName]
    $TermGroup = $TermStore.Groups[$TermGroupName]
    $TermSet = $TermGroup.TermSets[$TermSetName]

    # get the global navigation term set
        $GlobalNavigationTermGroup = $TermStore.Groups[$GlobalNavigationTermGroupName]
        $GlobalNavigationTermSet = $GlobalNavigationTermGroup.TermSets[$GlobalNavigationTermSetName]
        $GlobalNavigationTermSet = $TermGroup.TermSets[$GlobalNavigationTermSetName]

    # remove all the existing terms
    $TermSet.Terms | ForEach-Object{$_.delete()}

     # pin the terms from the master term set
     $GlobalNavigationTermSet.Terms | ForEach-Object{$TermSet.ReuseTermWithPinning($_) | Out-Null}

     # copy the sort order
     $TermSet.CustomSortOrder = $GlobalNavigationTermSet.CustomSortOrder 

     # update the navigation settings
     $WebNavigationSettings.GlobalNavigation.Source = 2
     $WebNavigationSettings.GlobalNavigation.TermStoreId = $TermStore.Id
     $WebNavigationSettings.GlobalNavigation.TermSetId = $TermSet.Id

     $WebNavigationSettings.AddNewPagesToNavigation = $false
     $WebNavigationSettings.CreateFriendlyUrlsForNewPages = $false

This function is part of my PowerShell PowerUp framework.


Leave a Reply