SharePoint - PowerShell script to organize QuickLaunch menu with Alpha Order

Steel Contributor

With File Server Migration to SharePoint Online, we can retrieve in SPO a large number of document libraries (to reduce issues with existing SPO limitations).

That is something acceptable from SPO point of view, but from user side, it could be quickly disturbing to find all those document libraries into the left menu without a clean order (in my case, it was more than 350 document libraries loaded).

One solution could be to simply apply an alphabetical order into this menu which is easy to explain to end users. With SharePoint web interface, that is really boring to do this ordering and PowerShell with PnP is perfect for.

 

You can find the script I developed that requirement, you can adapt with your specific requirement as you want.

 

[string]$SiteURL = "https://yourtenant.sharepoint.com/sites/YourSiteCollection/YourSubSite/"
[string]$TenantURL = "https://yourtenant.sharepoint.com"
$SpecialBasicMenuItems = "Documents", "Home"
[string]$RelativeSiteURL = $($SiteURL).Replace($TenantURL, "")

Connect-PnPOnline -Url $SiteURL  -UseWebLogin
$MenuList = Get-PnPNavigationNode -Location QuickLaunch

$OrderQuickLaunchMenu = $MenuList| Sort-Object -Property Title -Descending | Where-Object {$_.Title -NotIn $SpecialBasicMenuItems} 
$OrderQuickLaunchMenu

#Remove all old QuickLaunch Items (except exclusions define before)
foreach($MyQuickLaunchItem in $MenuList)
{
    Remove-PnPNavigationNode -Identity $MyQuickLaunchItem.Id -Force
}

#Add each Item with correct order
foreach($MyQuickLaunchItem in $OrderQuickLaunchMenu)
{
    Add-PnPNavigationNode -Title $MyQuickLaunchItem.Title -Url $MyQuickLaunchItem.Url -Location "QuickLaunch" -First

    #Remove-PnPNavigationNode -Identity $MyQuickLaunchItem.Id -Force
}

#Reset root Site Menus
Add-PnPNavigationNode -Title "Documents" -Url $($RelativeSiteURL+"Shared Documents/") -Location "QuickLaunch" -First
Add-PnPNavigationNode -Title "Home" -Url $($RelativeSiteURL) -Location "QuickLaunch" -First

When your script is adapted and executed, you will have all left menu items in the correct alphabetical order.

 

Fabrice Romelard

0 Replies