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
2. Go to Manage Service Applications
3. Select Managed Metadata Service Application.
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.
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
}
Happy Coding.
Sathish Nadarajan.
Leave a comment