Jesper M. Christensen

SharePoint and Security

Set SharePoint 2013 Navigation Settings from PowerShell


Hi everyone,

I just got a large SharePoint 2013 site to set up and wanted to set all the sites navigation settings through Windows PowerShell.

It seems to be quite easy, but when I set the “Current Navigation” settings to Structured the UI (user interface) settings page do not show these settings – it Works though, but is a bit confusing. Actually nothing is checked in the boxes, but for now I am good – hope I found out why this is happening. Anyone knows this?

navigationsettings

I use the script below to connect to a site Collection, set this navigation settings and afterwards all sub sites. This script do not handle Metadata Navigation.

################################################################
#
# Powershell script by Jesper M. Christensen
# Blog: http://JesperMChristensen.wordpress.com
#
# Set the SharePoint 2010 and 2013 Navigation Settings on Sites
#
# SetupNavigationSettings.ps1 version 1.0 - Edited January 2013
#
################################################################
Write-Host -ForegroundColor White "Set the SharePoint 2010 and 2013 Navigation Settings on Sites"

#Set the Site Collection
$SPSite = Get-SPSite -Identity "http://extrico-demo2.dev.extrico.local/sites/demo1"

#Go through each site in the Site Collection
foreach ($SPWeb in $SPSite.AllWebs)
{
if ($SPWeb.IsRootWeb)
{#Process the root web
Write-Host -ForegroundColor Gray $SPWeb.Url":" -NoNewLine
#Save the AllowUnsafeUpdatesStatus property value
$AllowUnsafeUpdatesStatus = $SPWeb.AllowUnsafeUpdates
$SPWeb.AllowUnsafeUpdates = $true

#Set the Publishing Web
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($SPWeb)

#Global Navigation Settings
$SPPubWeb.Navigation.InheritGlobal = $false
$SPPubWeb.Navigation.GlobalIncludeSubSites = $true
$SPPubWeb.Navigation.GlobalIncludePages = $false
$SPPubWeb.Navigation.GlobalDynamicChildLimit = 21

#Current Navigation Settings
#
# -Display the same navigation items as the parent site: InheritCurrent = $true and ShowSiblings = $false
# -Structural Navigation: Display the current site, the navigation items below the current site, and the current site's siblings: InheritCurrent = $false and ShowSiblings = $true
# -Structural Navigation: Display only the navigation items below the current site: InheritCurrent = $false and ShowSiblings = $false
#
$SPPubWeb.Navigation.InheritCurrent = $false
$SPPubWeb.Navigation.ShowSiblings = $true
$SPPubWeb.Navigation.CurrentIncludeSubSites = $false
$SPPubWeb.Navigation.CurrentIncludePages = $false
$SPPubWeb.Navigation.CurrentDynamicChildLimit = 21

# Sorting
$SPPubWeb.Navigation.OrderingMethod = "Manual" # "Automatic" "ManualWithAutomaticPageSorting"
$SPPubWeb.Navigation.AutomaticSortingMethod = "Title" # "CreatedDate" "CreatedDate" "LastModifiedDate"
$SPPubWeb.Navigation.SortAscending = $true

#Update the Publishing Web Navigation Settings
$SPPubWeb.Update()
Write-Host -ForegroundColor Green " Done"
}
else
{#Process all sub-webs to the root web

Write-Host -ForegroundColor Gray $SPWeb.Url":" -NoNewLine

#Save the AllowUnsafeUpdatesStatus property value
$AllowUnsafeUpdatesStatus = $SPWeb.AllowUnsafeUpdates
$SPWeb.AllowUnsafeUpdates = $true

#Set the Publishing Web
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($SPWeb)

#Global Navigation Settings
$SPPubWeb.Navigation.InheritGlobal = $true
$SPPubWeb.Navigation.GlobalIncludeSubSites = $true
$SPPubWeb.Navigation.GlobalIncludePages = $false
$SPPubWeb.Navigation.GlobalDynamicChildLimit = 21

#Current Navigation Settings
$SPPubWeb.Navigation.InheritCurrent = $false
$SPPubWeb.Navigation.ShowSiblings = $true
$SPPubWeb.Navigation.CurrentIncludeSubSites = $false
$SPPubWeb.Navigation.CurrentIncludePages = $false
$SPPubWeb.Navigation.CurrentDynamicChildLimit = 21

# Sorting
$SPPubWeb.Navigation.OrderingMethod = "Manual" # "Automatic" "ManualWithAutomaticPageSorting"
$SPPubWeb.Navigation.AutomaticSortingMethod = "Title" # "CreatedDate" "CreatedDate" "LastModifiedDate"
$SPPubWeb.Navigation.SortAscending = $true

#Update the Publishing Web Navigation Settings
$SPPubWeb.Update()
Write-Host -ForegroundColor Green " Done"
}

#Revert the AllowUnsafeUpdatesStatus property value
$SPWeb.AllowUnsafeUpdates = $AllowUnsafeUpdatesStatus

#Dispose the SPWeb object
$SPWeb.Dispose()
}

#Dispose the SPSite object
$SPSite.Dispose()
Advertisements

3 responses to “Set SharePoint 2013 Navigation Settings from PowerShell

  1. Eddie Narten February 17, 2013 at 13:52

    I also have this problem. The UI shows nothing, although it seems to work. Did you find a solution to this? Is it a bug?

  2. Roel Hans Bethlehem (@rbethleh) March 5, 2013 at 14:48

    Yup, API change. This code works for me on premise.

    SPSite site = new SPSite(“http://devbox”);
    SPWeb web = site.OpenWeb(“v9”);
    PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
    Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings navSetting = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(web);
    navSetting.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
    navSetting.Update();

    In my scenario I have to make it work from CSOM however (aka in new Office 365).

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

%d bloggers like this: