Clear the Quick Launch programmatically using PowerShell

Posted 21 March 2012 12:00 AM by James Callaghan, Consultant @ ClearPeople

Today I had a requirement to remove all the headings and links from the quick launch of SharePoint sites (webs) as they were being created by a PowerShell deployment script.

SharePoint sites

I knew it was possible as I did something similar on a project with SharePoint 2007. So you would have thought that it would have been a relatively simple task, however I didn’t have access to this previous script and couldn’t quite remember how I achieved it.

In the end I did a little research and found some example PowerShell scripts which were about working with the quick launch. One post from Get-SPScripts did what I was after but was part of a much larger script. In the end this is what I ended up with:

function Clear-QuickLaunch($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()

}

}

Clear-QuickLaunch “http://sharepoint/”

SharePoint Management Shell

I got off to a rather slow start as I had forgot to set the $Nodes variable to an empty array and PowerShell kept throwing this error.

This was because $Nodes = $Nodes + $_.Id was performing a sum calculation rather than building up an array of all the objects. All was resolved once I remembered to include $Nodes = @() before using the $Nodes variable as an array.

SharePoint sites

Share:

Add your comment

 
 

 

Archive

Tagcloud

Microsoft Teams Office 365 Yammer cms content management system agile GDPR Microsoft Graph collaboration Microsoft sharepoint 2016 upgrade migration SharePoint Online 2016 Tech Trends Digital Disruption Context marketing marketing SharePoint 2010 SharePoint 2013 TFS Git security kentico Analytics intranet jquery QA Quality Assurance testing digital workspace content management websites Sitecore sitecore marketplace sitecore module cloud Microsoft Cloud Storage digital strategy technical consulting sitecore modules Experience database Sitecore 7 Sitecore 8 support account management customer experience Data Storage windows azure cms integration front end front end development prototype Cloud Storage StorSimple Front-end Development Layout SharePoint 2013 colour palette UI design website design log viewer sitecore cms website Azure big data business-critical sharepoint accessibility android apple chrome clear people clearpeople debug emulator ios mobile testing opera resize adobe desktop flash ie10 internet explorer 10 metro windows 8 bcsp SharePoint Advanced System Reporter reporting framework ControlMode form control master page placeholder publishing console SharePoint 2007 SharePoint error search search results search values software testing testing scenario audit content information architecture retention schedules PowerShell QuickLaunch scripts SharePoint server 2010 business solutions metalogix replication replicator storagepoint stena technet UK Technet picture library slideshow web part RTM released to manufacturing caml caml query MOSS 2007 query infopath