Adjusting Quicklinks Programmatically in SharePoint

89

Use PowerShell to set Quicklinks Programmatically in SharePoint

Wouldn’t it be great to hide all lists of a certain type in a farm? Perhaps Tasks, Calendars or Discussions, or all of the above. Progrmmatically, they can be hidden or exposed on navigation using set_OnQuickLaunch(). Here’s how a given library is hidden from quick launch:

$LIB.set_OnQuickLaunch($false)

Let’s now do it across a full web application; all the site collections, sites, and for a set of libraries.

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
Start-SPAssignment –Global 

$mylogfile="C:logfolderongoinglogfile.txt"

$envrun="Prod"			# selects environment to run in
  
if ($envrun -eq "Dev")
{
$siteUrl = "http://devdocs.SharePoint.com"
$LibsToFlip = "Tasks,Site Pages,Calendar,Documents"

$LibsToFlipArray = $LibsToFlip.Split(“,”)
}
elseif ($envrun -eq "Prod")
{
$siteUrl = "http://docsny.SharePoint.com"

$LibsToFlip = "Tasks,Site Pages,Calendar,Documents,Team Discussion"
$LibsToFlipArray = $LibsToFlip.Split(“,”)
}
else
{
Write-Host "ENVIRONMENT SETTING NOT VALID: script terminating..."
$siteUrl =  $null;
return;
}

Write-Host "Quick Launch Flip script starting $(get-date)" 



if ($siteurl)
{
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication 
foreach($site in $spWebApp.Sites)
{
  write-host $site.Url

#  if ($site.Url -like "$siteurl/personal/*")  
  if ($site.Url -like "$siteurl*")  
{
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl);
$rootWeb = $rootSite.RootWeb;


 $webs= $site.AllWebs;
 $WebsCount = $webs.count;
 
 for ($wi=0; $wi -lt $WebsCount; $wi++)
   {
   $web = $webs[$wi]

   $changed = $false;
   
   $lists = $web.Lists;
   $listcount = $lists.count;
 	for ($li=0; $li -lt $listcount; $li++)
   { 
   $JPLib = $lists[$li]

	if ($libsToFlipArray -contains $JPLib.Title )
	{
	WRITE-HOST -ForegroundColor darkgreen "$($JPLib.Title) in $($web.url)"
	$JPLIB.set_OnQuickLaunch($false)
	$JPLib.Update()
	$changed = $true;
	}

 	}
 	if ($changed)
 	{
 		#$Web.update()
	}
 
}
}
}
}

Stop-SPAssignment –Global
###########################

Share this entry

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents

Categories

Categories