SharePoint Online: Delete a Link in Quick Launch or Top Navigation using PowerShell

Requirement: Remove a Node from SharePoint Online Top Navigation or Quick Launch bar.

Are you looking to delete a link in your SharePoint Online site’s quick launch or top navigation? Perhaps you have a link that you no longer want to appear in the navigation, or you want to hide a link from users. This blog post will show you how to use PowerShell to remove a link from the quick launch or top navigation in SharePoint Online.

How to Remove Links from SharePoint Online Navigation?

To remove links from SharePoint Online site navigation, follow these steps:

  1. Sign in to your SharePoint Online site as a site owner or administrator.
  2. Click on the “Edit” link at the end of your left navigation or top navigation bar.
    how to edit left navigation in sharepoint online
  3. Hover over the link that you want to remove in the navigation >> Click on the little three dots >> from the context menu, choose “Remove”.
    sharepoint online remove navigation links
  4. Click “Save” to save the changes.

The link should now be removed from the Quick Launch or Top Navigation bar in your modern SharePoint Online site.

Following the steps outlined above, you can easily remove a link from the Quick Launch or Top Navigation in SharePoint Online, giving you greater control over your site’s navigation and organization.

Remove Links from Navigation when Publishing Feature is Active

When the publishing feature is active, things work slightly differently:

  1. Go to Site Settings >> Click on the “Navigation” from Look and feel (You may have to use the “Top link bar” if the publishing feature is not enabled!)
  2. Select the navigation node or link in either global navigation (Top navigation) or from current navigation (Quick Launch)
  3. Click on the “Delete” icon to delete the link from the navigation. 
  4. Click on the “OK” button at the bottom of the page to save your changes.

PowerShell to Delete a Navigation Node in SharePoint Online

Here is the PowerShell to remove a node from quick launch or top navigation in SharePoint Online:

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

#Remove Link from Navigation
Function Remove-SPONavigationNode()
{
    Param([Microsoft.SharePoint.Client.NavigationNodeCollection]$Navigation, [String]$NavigationTitle)

    #Iterate through and Remove the Node from Navigation
    For($i = $Navigation.Count - 1; $i -ge 0; $i--)
    {
        If($Navigation[$i].Title -eq $NavigationTitle)
        {
            $Navigation[$i].DeleteObject()
            $Ctx.ExecuteQuery()
            Write-Host -f Green "Removed " $NavigationTitle 
        }
        Else
        {
            #Check in 2nd Level Links
            $ChildLinks = $Navigation[$i].Children
            $Ctx.Load($ChildLinks)
            $Ctx.ExecuteQuery()

            #Call the function recursively
            If($ChildLinks.Count -gt 0)
            {
                Remove-SPONavigationNode -Navigation $ChildLinks -NavigationTitle $NavigationTitle
            }
        }
    }
}
 
#Config Parameters
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the Top Navigation bar of the web
$TopNavigation = $Ctx.Web.Navigation.TopNavigationBar #For Quick Launch, use: $Ctx.Web.Navigation.QuickLaunch
$Ctx.load($TopNavigation)
$Ctx.ExecuteQuery()

#Call the function to Remove a Node from navigation
Remove-SPONavigationNode -Navigation $TopNavigation -NavigationTitle "Support Center"

This PowerShell removes given navigation nodes and all its child nodes!

Let’s remove the “Site Contents” link, which points to “/_layouts/15/viewlsts.aspx” from the left navigation in the SharePoint Online site with PnP PowerShell cmdlet Remove-PnPNavigationNode.

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$LinkTitle = "Site contents"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get Quick Launch Navigation
$NavigationNodeCollection = Get-PnPNavigationNode -Location QuickLaunch

#Get the Link to Delete
$NavigationNode = $NavigationNodeCollection | Where-Object { $_.Title -eq  $LinkTitle}

#Delete Link from left navigation 
Remove-PnPNavigationNode -Identity $NavigationNode.Id -Force

This time, let’s delete the “Home” link from the top navigation bar of a SharePoint Online site.

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$LinkTitle = "Home"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Top Navigation Bar
$NavigationNodeCollection = Get-PnPNavigationNode -Location TopNavigationBar

#Get the Link to Delete
$NavigationNode = $NavigationNodeCollection | Where-Object { $_.Title -eq  $LinkTitle}

#Delete Link from Top navigation 
Remove-PnPNavigationNode -Identity $NavigationNode.Id -Force

To add a new link to the left navigation or top navigation bar, use: How to Add a Link to Quick Launch Navigation in SharePoint Online using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “SharePoint Online: Delete a Link in Quick Launch or Top Navigation using PowerShell

  • First off thanks for all of your contributions. I’ve learned quite a deal from your offerings. I’m am trying to make the script from this one into a for each that loops through a batch of sites in a csv file to updatea shared TopNavigationBar link.
    Thanks in advance

    Reply
  • How to identify who removed the link from the navigation bar? Is the editing navigation audited?

    Reply

Leave a Reply

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