How to Map Page Layouts to Terms for Navigation in SharePoint 2013 using PowerShell

Sathish Nadarajan
 
Solution Architect
February 3, 2015
 
Rate this article
 
Views
10883

In this article, let us see how to Map the Page layouts for various Terms using Powershell in SharePoint 2013.

Before diving into the Script, let us see, how to do that using the User Interface.

1. Go to Central Admin

image

2. Go to Manage Service Applications

image

3. Select Managed Metadata Service Application.

image

4. Select the TermSet and on the Intended Use Tab, Select the Check Box, “Use this Term Set for Site Navigation”

5. Now, select any of the Term and on the “Term Driven Pages” Tab select the check boxes and give the appropriate URLS.

image

Now, the same thing, let us see how to do that using PowerShell.

The script is as follows.

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".UpdateTermSet-$LogTime.rtf"
 
 
 cls
 
 
 ##================================================================================================
 ## Description	: This script is used to Set the TermSet for the Navigation and Set the Catalog, Item Page URLs.
 ## Author		: Sathish Nadarajan
 ## Date			: 15-Dec-2014
 ##================================================================================================
 
 
  
 $Host.UI.RawUI.WindowTitle = "-- Set Term URLs --"
 
 $StartDate = Get-Date
 Write-Host -ForegroundColor White "------------------------------------"
 Write-Host -ForegroundColor White "| Update the Navigation Tag and Catalog, Item Page URLs |"
 Write-Host -ForegroundColor White "| Started on: $StartDate |"
 Write-Host -ForegroundColor White "------------------------------------"
 
 
 
 #start-transcript $logfile
 
 $ErrorActionPreference = "Stop"
 ######################### Add SharePoint PowerShell Snapin ###############################################
 
 if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) 
 {
     Add-PSSnapin Microsoft.SharePoint.Powershell
 }
 
 ########################### End of Add SharePoint PowerShell Snapin ##################################
 
 ######################## Set Execution Path ################################################
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 
 
 function UpdateTerms([string] $caURL,[string] $groupName,[string] $termsetName,[string] $termGUID, [string] $ChangeCatalogTargetURL,[string] $ChangeCatalogTargetUrlForChildTerms,[string] $ChangeTargetURL,[string] $ChangeTargetUrlForChildTerms, [string] $CatalogTargetUrl, [string] $CatalogTargetUrlForChildTerms, [string] $TargetUrl, [string] $TargetUrlForChildTerms)
 {
 
     $caSite = Get-SPSite -Identity $caURL
 
     $taxonomySession = Get-SPTaxonomySession -Site $caSite
  
     $termStore = $taxonomySession.DefaultKeywordsTermStore
  
     $termStoreGroup = $termStore.Groups[$groupName]
  
     $termset = $termStoreGroup.TermSets[$termsetName]
  
     $termset.SetCustomProperty("_Sys_Nav_IsNavigationTermSet", "True")
 
     $term = $termset.GetTerm($termGUID)
  
     Write-Host "Going to Update the Term :- " $term.Name -ForegroundColor Yellow
 
     $term.SetLocalCustomProperty(“_Sys_Nav_CatalogTargetUrl”, $CatalogTargetUrl)
 
     if($ChangeCatalogTargetUrlForChildTerms -eq $true)
     {
         $term.SetLocalCustomProperty(“_Sys_Nav_CatalogTargetUrlForChildTerms”, $CatalogTargetUrlForChildTerms)
     }
  
     #$term.SetLocalCustomProperty(“_Sys_Nav_CategoryImageUrl”, “~sitecollection/Images/Test.png”)
  
     $term.SetLocalCustomProperty(“_Sys_Nav_TargetUrl”, $TargetUrl)
  
     if($ChangeTargetUrlForChildTerms -eq $true)
     {
         $term.SetLocalCustomProperty(“_Sys_Nav_TargetUrlForChildTerms”, $TargetUrlForChildTerms)
     }
  
     
 
     
 
     #$term.SetLocalCustomProperty(“_Sys_Nav_ExcludedProviders”, "false")
 
     #$term.LocalCustomProperties
 
     $termStore.CommitAll()
 
     Write-Host "Updated the Term :- " $term.Name -ForegroundColor Green
 }
  
 
 
 $UpdateTermsCSV = $scriptBase + "" + "MapPageLayoutsToTerms.csv"
 
 import-csv $UpdateTermsCSV | where {
     UpdateTerms $_.CentralAdminUrl $_.TermGroupName $_.TermSetName $_.TermGUID $_.ChangeCatalogTargetURL $_.ChangeCatalogTargetUrlForChildTerms $_.ChangeTargetURL $_.ChangeTargetUrlForChildTerms $_.CatalogTargetUrl $_.CatalogTargetUrlForChildTerms $_.TargetUrl $_.TargetUrlForChildTerms
 
 
     											
 
 
     
 }
 

Download HERE

Happy Coding.

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment