Let us explore how to add left navigation or quick launch links using PowerShell to all SharePoint sites and subsites.
Add left navigation or quick launch links using PowerShell to all SharePoint sites
In SharePoint Online, we can easily add a link in the left navigation using PowerShell. It will add in all sites and subsites under a particular SharePoint site collection.
Here we will use the CSOM PowerShell, using Windows PowerShell ISE.
Below is the PowerShell script which will add links to left navigation into the SharePoint Online sites and subsites.
#Load SharePoint CSOM Assemblies
Add-Type -Path "D:\Microsoft.SharePoint.Client.dll"
Add-Type -Path "D:\Microsoft.SharePoint.Client.Runtime.dll"
$username = "user email id"
$password = "password"
$SiteCollectionUrl="http://siteurl"
function GetClientContext($SiteCollectionUrl, $username, $password) {
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollectionUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$context.Credentials = $credentials
return $context
}
function catchsubsites ($subsiteurl){
$clientContext = GetClientContext $subsiteurl $username $password
$rootWeb = $clientContext.Web
$childWebs = $rootWeb.Webs
$clientContext.Load($rootWeb)
$clientContext.Load($childWebs)
$clientContext.ExecuteQuery()
#do something on top level site
#write-host $rootWeb.url -ForegroundColor Yellow
foreach ($childWeb in $childWebs)
{
#do something for each subsite
write-host $childWeb.url -ForegroundColor Yellow
#Get the Quick launch Navigation of the web
$QuickLaunch = $childWeb.Navigation.QuickLaunch
$clientContext.load($QuickLaunch)
$clientContext.ExecuteQuery()
#Add link to Quick Launch Navigation
$NavigationNode = New-Object Microsoft.SharePoint.Client.NavigationNodeCreationInformation
$NavigationNode.Title = "New link"
$NavigationNode.Url = "https://LINK"
#$NavigationNode.AsLastNode = $False
$clientContext.Load($QuickLaunch.Add($NavigationNode))
$clientContext.ExecuteQuery()
#see if there are any subsites beneath this and loop all of them too
catchsubsites $childWeb.url
}
}
catchsubsites $SiteCollectionUrl
Once you run the above script, the link will be added to the quick launch in all the SharePoint sites and subsites under the SharePoint site collection.
You may like the following SharePoint tutorials:
- How to hide Notebook and Site contents from quick launch in SharePoint Online
- Remove Notebook link from quick launch in SharePoint
- Add Recycle Bin link in quick launch in SharePoint 2013/2016/Online
- SharePoint 2013 Left Navigation or Quick Launch Menu Customization
- How to disable quick edit in SharePoint list
- Change content type recursively using PowerShell SharePoint 2013
- Get sharepoint site template PowerShell
- How to Change SharePoint Site Logo + PowerShell
- How to remove SharePoint Online Modern Page Title using PowerShell
- Enable or Disable List Throttling using PowerShell in SharePoint
The turning point in the process of growing up is when you discover the core of strength within you that survives all hurt.