SharePoint Online: Change Navigation Settings using PowerShell
Requirement: SharePoint Online Set navigation using PowerShell.
How to Change Navigation in SharePoint Online?
SharePoint Online has the ability to customize navigation to make it easier for users to find and access the content. In this blog post, we will show you how to change the navigation in SharePoint Online. We will also show you how to set navigation options for a site using PowerShell.
To change the navigation in SharePoint Online, Go to:
- Site Settings >> “Navigation” under “Look and Feel” group
- Set the navigation settings for global navigation and current navigation accordingly.
SharePoint Online: Set Navigation using PowerShell
Here is the PowerShell to set SharePoint Online navigation:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Publishing.dll"
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing/2018"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the Web
$Web = $Ctx.Web
$ctx.Load($Web)
$Ctx.ExecuteQuery()
$TaxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
$NavigationSettings = New-Object Microsoft.SharePoint.Client.Publishing.Navigation.WebNavigationSettings($Ctx, $Web)
#Set Both current and global navigation settings to structural - Other values: PortalProvider,InheritFromParentWeb ,TaxonomyProvider
$NavigationSettings.GlobalNavigation.Source = "PortalProvider"
$NavigationSettings.CurrentNavigation.Source = "PortalProvider"
#Show subsites in Global navigation
$Web.AllProperties["__IncludeSubSitesInNavigation"] = $True
#Show pages in global navigation
$Web.AllProperties["__IncludePagesInNavigation"] = $False
#Maximum number of dynamic items to in global navigation
$web.AllProperties["__GlobalDynamicChildLimit"] = 15
#Update Settings
$Web.Update()
$NavigationSettings.Update($TaxonomySession)
$Ctx.ExecuteQuery()
Write-host -f Green "Navigation Settings Updated!"
}
Catch {
write-host -f Red "Error Updating Navigation Settings!" $_.Exception.Message
}
Wrapping up
In this article, we have discussed how to change navigation settings in SharePoint Online using PowerShell. The steps outlined in this guide allow you to easily and quickly change a site’s navigation settings. You can automate this process using PowerShell and make your SharePoint Online environment easier to manage and maintain.
Hi Rajack,
How can we do the same with PnP PowerShell.
Like changing the current navigation settings in SharePoint Online site using PnP PowerShell.
Thanks,
Nirmala
Here is how you can use PnP PowerShell for the above script:
Thanks Rajack. I could get the sub sites and pages settings to be changed.
I am trying to change the current navigation property from “Display the same navigation items as the parent site” to “Structural Navigation: Display only the navigation items below the current site” and couldn’t find the proper options with PnP PowerShell.
Any help is greatly appreciated..
Nirmala