How to change the JSLink property of the Blog posts Web part in Default.aspx page of a blog site using powershell ? I tried the code below

$SPsite = Get-SPWeb -Identity "http://blogpostsiteurl"  
  $webpartmanager = $SPsite.GetLimitedWebPartManager("/default.aspx",   

  for($i=0;$i -lt $webpartmanager.WebParts.Count;$i++)  {   
  if($webpartmanager.WebParts[$i].title -eq "Posts")   

But i get the error

Exception calling "GetLimitedWebPartManager" with "2" argument(s): "Value does
not fall within the expected range."

Can someone help me with what I am doing wrong?


1 Answer 1


After some research , I got it

   $SiteURL = "http://blogsiteurl"  

    Function SetJSLinkPropertyOnPostsWebPart($SiteURL)

        $pagePath = "/default.aspx"
        $pageUrl = $SiteURL + $pagePath
        $web = Get-SPWeb $SiteURL

        $spWebPartManager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

        foreach ($webpart in ($spWebPartManager.WebParts | Where-Object {$_.Title -eq "Posts"}))

    SetJSLinkPropertyOnPostsWebPart $SiteURL

Your Answer

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

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