Populating the QuickLaunch in SharePoint with PowerShell

The following snippet shows how you might re-write the contents of the Quick Launch within SharePoint on-prem. It’s pretty straightforward – just duplicate the parent and child lines for as many links as you need.

# Connect to Site
$web = get-spweb "https://server/sites/site_collection/subsite"

# Get the quicklaunch
$quicklaunch = $web.Navigation.QuickLaunch

# Remove all items in the quicklaunch
($quicklaunch | where {$_.Title -ne ""}).Delete() > $null

# Create a parent link
$navnode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Home", $web.Url, $false)
$parent_link = $quicklaunch.AddAsLast($navnode)

# Create a child link
$navnode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Link to a List", $($web.Url + "/lists/mylist"), $false)
$child_link = $parent_link.Children.AddAsLast($navnode)

# You can switch Quick Launch on and off entirely
$web.QuickLaunchEnabled = $true

# Write the changes to the web

# Release resources
Posted by Jonathan Beckett in Notes, 0 comments