Created
January 20, 2015 19:34
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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