2

I am working on a PowerShell script to provision a site collection with a predefined hierarchy. Since the PowerShell breadth is so limited, most of this is done via functions that are CSOM code.

As part of this, I need to have a unified global navigation. I have been able to enable the publishing feature without problems. My issues arise when I have to step through each site and set the global navigation settings to:

  1. Use structural navigation on the Rootweb, including subsites
  2. In each subsite, inherit from the parent, and include subsites.

I have seen a lot of this floating around for on-prem like Powershell script to update Navigation.GlobalIncludeSubSites not applying change, I need it to work for Office 365. I can't seem to get a right handle on the publishing web and the navigation settings.

Does anyone have a definitive example or a reference to how to modify the current navigation via CSOM in PowerShell for Office 365?

3

In SharePoint 2013 was introduced a new Microsoft.SharePoint.Client.Publishing and Microsoft.SharePoint.Client.Publishing.Navigation namespaces in CSOM API. But unfortunately it is not supported to get/set Show subsites & Show pages navigation settings using WebNavigationSettings class since those properties are not exposed.

Having said that I propose to utilize ClientPortalNavigation.cs which represents a CSOM counterpart for SSOM PortalNavigation Class which in turn allows to get/set navigation settings including Show subsites & Show pages navigation settings.

Implementation

In order to consume ClientPortalNavigation.cs in PowerShell below is demonstrated how to implement it as a custom PowerShell snap-in.

  • Build an assembly from SharePoint.Client.Navigation.PowerShell project
  • Install the specified assembly using Installer Tool:InstallUtil SharePoint.Client.Navigation.PowerShell.dll
  • Register Windows PowerShell snap-in:Add-PsSnapin SharePoint.Client.Navigation.PowerShell

Usage

The example demonstrates how to set SharePoint Online Global navigation Show subsites & Show pages settings via CSOM API in PowerShell:

if ((Get-PSSnapin -Name SharePoint.Client.Navigation.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PsSnapin SharePoint.Client.Navigation.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
   $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
   return New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
}

$UserName = "username@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.sharepoint.com/"
$credentials = Get-SPOCredentials -UserName $UserName -Password $Password
SetGlobalNavigation -Url $Url -Credentials $credentials -IncludePages $true -IncludeSubSites $true 

References

Access and Manipulate Navigation Settings via SharePoint Client Object Model

  • I can build it, I just can't seem to get PowerShell to recognize it to try it. – Eric Alexander Aug 5 '15 at 14:46
  • Probably it could not be recognized by PowerShell since it should be installed using x64 version of InstallUtil.exe (more details) – Vadim Gremyachev Aug 5 '15 at 15:10
  • I'll keep trying, would gacutil work too? – Eric Alexander Aug 5 '15 at 19:28
  • Eric, for some reason i haven't noticed your last comment, gacutil should work as well. – Vadim Gremyachev Sep 9 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.