SharePoint Online: Change Navigation Settings using PowerShell

Requirement: SharePoint Online Set navigation using PowerShell

How to Change Navigation in SharePoint Online?

To change 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 powershell

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= ""

#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

    $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

    Write-host -f Green "Navigation Settings Updated!"
Catch {
    write-host -f Red "Error Updating Navigation Settings!" $_.Exception.Message

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “SharePoint Online: Change Navigation Settings using PowerShell

  • Hi Rajack,

    How can we do the same with PnP PowerShell.
    Like changing the current navigation settings in SharePoint Online site using PnP PowerShell.


    • Here is how you can use PnP PowerShell for the above script:

      #Connect to PnP Online
      Connect-PnPOnline -Url $SiteURL -Interactive
      #Get the Web
      $web = Get-PnPWeb
      #Show subsites in Global navigation
      $Web.AllProperties["__IncludeSubSitesInNavigation"] = $True
      • 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..



Leave a Reply