Get,Add & Remove Navigation Using PnP-Powershell

Introduction :

    In this blog, I have discussed how to add, retrieve, and delete the SharePoint navigation menu using PowerShell. Follow the steps to get the result.

Steps :

1. Get the Navigation Node

2. Add the Navigation

3. Remove/Delete the Navigation

   In this blog, added the coding of HubNavigation Menu but you can also Add, Retrieve and Delete the footer, Top and Hub Navigation menu from your site by running the script.

Get Top Navigation Node : 

     Follow the below code to get the Hub Navigation menu.   

 $siteURL = Read-Host “Enter site url”

try{

    Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)

    #Get Hub Navigation and Its Sub Menu

    $topNavsMenu = Get-PnPNavigationNode -Location TopNavigationBar | Select Title,Url,Id

    foreach($topNav in $topNavsMenu)

    {

       Write-Host “Top Navigaion : ” $topNav.Title

       $node = Get-PnPNavigationNode -Id $topNav.Id

            $childMenus = $node.Children | Select Title, Url, Id

            if($childMenus -ne $null){

                foreach($childMenus in $node.Children)

                { 

                   Write-Host “SubNavigation : ” $childMenus.Title

                   $subNodeMenus = Get-PnPNavigationNode -Id $childMenus.Id

                   $subchilds = $subNodeMenus.Children | Select Title, Url, Id

                   if($subchilds -ne $null){

                        foreach($childMenus in $subchilds)

                          {

                            Write-Host $childMenus.Title

                          }

                    }

                }

             }

     }

}

catch{}

     It is retrieving Hub navigation top, sub & child menu.

 For Quick Lunch Menu:

  $quicklunch =  Get-PnPNavigationNode -Location QuickLaunch

  Write-Host $quicklunch.Title

For footer Navigation :

 $footerNav =  Get-PnPNavigationNode -Location Footer

  Write-Host $footerNav.Title

For Search Navigation :

 $searchNav =  Get-PnPNavigationNode -Location SearchNav

  Write-Host $searchNav.Title 

Add Navigation Node :

Follow the code mentioned below to add the navigation node

 $siteUrl = Read-Host “Enter site url”

try{

Connect-PnPOnline -Url $siteUrl -Credentials (Get-Credential)

Add-PnPNavigationNode -Location TopNavigationBar -Title “HubNavigation” -Url “https://www.google.com

}

catch{}

Remove Navigation Node :

Follow the code mentioned below to remove navigation node

 $siteUrl = Read-Host “Enter site url”

try{

Connect-PnPOnline -Url $siteUrl -Credentials (Get-Credential)

$navMenus = Get-PnPNavigationNode -Location TopNavigationBar | Select Title,Url,Id

$deleteNavNode = $navMenus | Where-Object { $_.Title -eq “HubNavigation” }

Remove-PnPNavigationNode -Identity $deleteNavNode.Id -Force

}

catch{}

Conclusion :

Here we have given the dynamic way to add, retrieve, and delete the SharePoint online navigation menu. As we are using the PowerShell PnP for this it easier to perform this as well as time effective.

Key Words:

  1. Get,Add & Delete navigation of SharePoint online using PnP PowerShell
  2. Add,Get and remove navigation with powershell
  3. Connecting pnp online Add,Get and remove navigation node of sharepoint online

Leave a Reply

Your email address will not be published. Required fields are marked *