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?
To remove links from SharePoint Online site navigation,
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.
This PowerShell removes given navigation nodes and all its child nodes!
PnP PowerShell to Delete a Link in Quick Launch Navigation
Lets remove the "Site Contents" link which points to "/_layouts/15/viewlsts.aspx" from the left navigation in SharePoint Online site.
Remove Link from Top Navigation using PnP PowerShell
This time, lets delete the "Home" link from top navigation bar of a SharePoint Online site.
How to Remove a Link from SharePoint Online Top Navigation or Quick Launch Bar?
To remove links from SharePoint Online site navigation,
- Go to Site Settings >> Click on " Navigation" from Look and feel (You may have to use "Top link bar" if 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 "Delete" icon to delete the link from 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://crescenttech.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
Lets remove the "Site Contents" link which points to "/_layouts/15/viewlsts.aspx" from the left navigation in SharePoint Online site.
#Config Variables $SiteURL = "https://crescenttech.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, lets delete the "Home" link from top navigation bar of a SharePoint Online site.
#Config Variables $SiteURL = "https://crescenttech.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
No comments:
Please Login and comment to get your questions answered!