Skip to content

Instantly share code, notes, and snippets.

@kasuken
Created January 20, 2015 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasuken/0898d25e6185df80f359 to your computer and use it in GitHub Desktop.
Save kasuken/0898d25e6185df80f359 to your computer and use it in GitHub Desktop.
Apply a JS Link file to all document library in all site of a site collection
#Load powershell snapin
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#Get site collection details
$site = Get-SPSite http://mysite
#Get all web sites in the site collections
$websites = $s.AllWebs
foreach($website in $websites)
{
Write-Host $website.Title -foreground Yellow
#loopthrouh the lists and libraries in the site
foreach($l in $website.Lists)
{
#Check for only document libraries
if($l.BaseTemplate -eq "DocumentLibrary" -and $l.Title -ne "Site Assets")
{
Write-Host "Processing " + $l.RootFolder.Name + " ..." -foreground Green
$webPartPage = $l.RootFolder.Name + "/Forms/AllItems.aspx"
Write-Host $webPartPage + " OK" -foreground Gray
$file = $website.GetFile($webPartPage)
#$file.CheckOut()
$webPartManager = $website.GetLimitedWebPartManager($webPartPage, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $webPartManager.WebParts[0]
$webpart.JSLink = "~SiteCollection/_catalogs/masterpage/linkfile.js"
$webPartManager.SaveChanges($webpart)
#$file.CheckIn("Awesomeness has been delivered")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment