SharePoint Online: Change Navigation Settings using PowerShell

Requirement: SharePoint Online Set navigation using PowerShell

How to Change Navigation in SharePoint Online?

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

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.

    Thanks,
    Nirmala

    Reply
    • 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
      $Web.Update()
      Invoke-PnPQuery
      
      Reply
      • 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

        Reply

Leave a Reply