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 = "[email protected]"
$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