I need to use the js for all views in all libraries in a site. Is there a way to deploy this in one hit rather than editing each view individually?

2 Answers 2


You can use powershell:

$site = Get-SPSite http://mysite
$web = $site.OpenWeb()
$list = $web.Lists["List Name"]
$wp = $list.RootFolder.Name + "/Forms/AllItems.aspx"
$wpManager = $website.GetLimitedWebPartManager($wp, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $wpManager.WebParts[0]
$webpart.JSLink = "~SiteCollection/_catalogs/masterpage/myScript.js"

You can loop throught your lists to add the js script.

  • Thanks how do I specify a specific site?
    – Mike Blair
    Commented Apr 23, 2015 at 14:43
  • updated my answer
    – Nk SP
    Commented Apr 23, 2015 at 14:46
  • I am getting these errors You cannot call a method on a null-valued expression. Cannot index into a null array. The property 'JSLink' cannot be found on this object. Verify that the property exists and can be set. Any ideas?
    – Mike Blair
    Commented Apr 23, 2015 at 15:09
  • The $webpart is null execute the script line for line to check if you retrive the right object
    – Nk SP
    Commented Apr 23, 2015 at 15:11

Change $website to $web , the final script will look like below :

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = Get-SPWeb http://sharepointsite
$list = $web.Lists["TestJSLink"]
$wp = $list.RootFolder.Name + "/Forms/AllItems.aspx"
$wpManager = $web.GetLimitedWebPartManager($wp, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $wpManager.WebParts[0]
$webpart.JSLink = "~layouts/XYZ/JSLink.js"
Write-Output "Done"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.