I will show you how to
Update JS Link of Site in SharePoint 2013 with Powershell. First
Open your SharePoint site and create a list from the Tasks template shown on
the below picture:
Name it My Tasks
And then, you’ll get
the tasks list as shown on the below picture:
Now, copy the URL of
the list. We will need it in the next step.
Note: Please note that we require %20 also to denote the space character.
Note: Please note that we require %20 also to denote the space character.
After that, copy
HelloWorld.js. Create a HelloWorld.js file and copy it to the Site Assets
library.
Now, open the PowerShell ISE editor and write the following code:
#
Add Snapin
if
((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction
SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
#
Update Page
$web
= Get-SPWeb http://sharepoint
$page
= "/Lists/My%20Tasks/AllItems.aspx"
$file
= $web.GetFile($page)
$file.CheckOut();
$manager
= $web.GetLimitedWebPartManager($page,
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart
= $manager.WebParts[0]
$webpart.JSLink
= "/siteassets/helloworld.js"
$manager.SaveChanges($webpart);
$file.CheckIn("JS
Link updated");
Change the Server URL
appropriately and run the code. If the code is executed with success, you’ll
get your page updated. You can verify the page update by opening the page in
edit mode. go to the web part properties and you’ll see that the JavaScript
link was updated there.
This concludes the JavaScript Link updating using PowerShell.
No comments:
Post a Comment