Sharepoint 2013 powershell script to add 'links' list under quicklaunch

spencer souvannarath 1 Reputation point
2021-08-06T19:08:34.85+00:00

I am having trouble figuring out how to add the links list from each subsite, into the quicklaunch.

I want to run a powershell script, for-*each subsite found under a site, add the "Links" list to the quick launch shortcut.

I need to take the managed-path for each subsite into consideration also.

Can someone please point me in the right direction on this?

Microsoft 365 and Office SharePoint Server For business
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Allen Xu_MSFT 13,861 Reputation points
    2021-08-09T07:51:53+00:00

    Hi @spencer souvannarath ,

    Do you mean that there is a list named "Links" in each of your subsites? The below code can used to add a list named "Links" to the quick launch of $weburl.

    $weburl = "http://sp"                              
    $list = "Links";                                          
    $w = get-spweb $weburl   
                             
    $ql = $w.Navigation.QuickLaunch;   
                           
    $urllink= $weburl + '/Lists/' + $list                  
    $cn = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($list,$urllink,$true);                 
    $ql.AddAsfirst($cn);  
    

    To add list to quick launch of all subsites in bulk, as the URL of Links lists are in the format of http://<weburl>/<subsitename>/Lists/Links, you can add a variable say "$subsitenames", put all subsitenames in an array, use foreach() to traverse all subsites and set the variable $urllink. Take a reference to the below sample code.

    $weburl = "http://sp"              
    $subsitenames = @('subsite1','subsite2','subsite3');              
    $list = "Links";              
                                
    foreach($subsite in $subsitenames){   
        
      $subsiteurl = $weburl + '/' + $subsite  
      
      $w = get-spweb $subsiteurl  
        
      $ql = $w.Navigation.QuickLaunch;   
      
      $urllink= $subsiteurl + '/Lists/' + $list    
      
      $cn = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($list,$urllink,$true);  
                 
      $ql.AddAsfirst($cn);  
         
      $w.Update()       
    }  
    

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.