Clear the SharePoint Quick Launch using PowerShell

The estimated reading time for this post is 1 minutes

Today I had a requirement to remove all the headings and links from the quick launch navigation of hundreds of SharePoint sites. The sites were being provisioned as part of a PowerShell deployment script that was deleting the default list and libraries. Going through each of these sites manually was not an option – so I edited the deployment script to include a function to remove the headings for me.

SharePoint Quick Launch with Headings
SharePoint Quick Launch with Headings

I remembered doing something similar to this back on SharePoint 2007 but I didn’t have access to the previous script or project and instead had to research the subject for a while to find what I needed.

Solution

A post from Get-SPScripts supplied me with what I was after, although it was part of a much larger script. So I picked away at their code and made it into the following PowerShell function to re-use in other projects.

[code lang=”powershell”]
function Remove-SPQuickLaunchLinks($url){
$SPWeb = Get-SPWeb $url
$QuickLaunch = $SPWeb.Navigation.QuickLaunch
$Nodes = @()

$QuickLaunch | ForEach-Object {
$Nodes = $Nodes + $_.Id
}

$Nodes | ForEach-Object {
$Node = $SPWeb.Navigation.GetNodeById($_)
$Node.Delete()
}
$SPWeb.Dispose()
}

Remove-SPQuickLaunchLinks "http://sharepoint.jcallaghan.com/"
[/code]

The above Remove-SPQuickLaunchLinks function will remove all headings and links from the SharePoint quick launch for a particular site.

Empty SharePoint Quick Launch
Empty SharePoint Quick Launch

Download

You can download the script here. Remember to review, rename and test this script before using it in a production environment.

Published by

James Callaghan

Father, blogger, consultant, SharePoint, Azure, Office 365 and PowerShell specialist, troubleshooter, geek, home brewer and would be amateur chef.

One thought on “Clear the SharePoint Quick Launch using PowerShell”

Leave a Reply