1

I have some bug on pages that uses custom Content type. I have fixed that bug by just 1). removing that custom content type from pages library, 2). Refreshes the page and then 3). By adding the same content type again. By following these steps I have fixed the bug. I have same problem on 150 sites, so i decided to write powershell script instead performing these steps manually on all 150 sites.

So, I have written Powershell script that follows the above steps where I walk through all the sites in a web application and remove a custom content type from Pages library. After removing content types from all 150 sites, i want to refresh all these sites (as step 2 above). How I refresh all 150 sites using Powershell?

  • What do you mean by "refresh"? HTTP Context is not available in PowerShell. – Paul Strupeikis Feb 19 '16 at 10:34
1

So what you meant by refresh is pushing changes to the children content types. You can push changes to children via PowerShell script. See example below.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    //get the specific Root web
    $spweb= Get-SPWeb "http://your.site.com"
    //get the fields collection
    $fields = $spWeb.Fields
    //get the specific field
    $field = $fields.GetFieldByInternalName("Name of you field")
    //get the specific Content Types from Root Web
    $contentType = $spWeb.ContentTypes["You Content Type"]
    //delete a field from a Content Type
    $contentType.FieldLinks.Delete($field) 
   //add a field to a Content Type
    $contentType.FieldLinks.Add($field)
    //update the Content Type and push changes to the children                                     
    $contentType.Update($true)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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