SharePoint Online: Delete Link in Quick Launch or Top Navigation using PowerShell
Requirement: Remove a Node from SharePoint Online Top Navigation or Quick Launch bar.
How to Remove a Link 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.
To remove links from SharePoint Online site navigation, follow these steps:
- Go to Site Settings >> Click on the “Navigation” from Look and feel (You may have to use “Top link bar” if the publishing feature is not enabled!)
- Select the navigation node or link in either global navigation (Top navigation) or from current navigation (Quick Launch)
- Click on the “Delete” icon to delete the link from the navigation.
- Click on “OK” button in 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!
PnP PowerShell to Delete a Link in Quick Launch Navigation
Let’s remove the “Site Contents” link, which points to “/_layouts/15/viewlsts.aspx” from the left navigation in SharePoint Online site.
#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
Remove Link from Top Navigation using PnP PowerShell
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