As you maintain your SharePoint 2010 site, over time you may be changing properties of web parts that appear on the site. Whether those have been developed in house or third party – if the instance of the web part appears in 50 pages in the site – it can be a real challenge to modify the properties of them manually.
Creating custom solution that will provision the change programmatically can be an option but there is a down time associated with such solution deployment which can be an issue if your site is in production.
In this example I will share a PowerShell script which will iterate through the publishing sites in the site collection and update the properties of the Content Editor web part. When done – the page will be checked back in and published to the site.
In the part of the script below I will show only the part where we change the properties of the web part – the rest of the working script you can download from here:
function UpdateWebpart([Microsoft.SharePoint.Publishing.PublishingPage]$page)
{
if($page.CheckOutBy -eq $null)
{
$page.CheckOut()
}
$webpartmanager=$web.GetLimitedWebPartManager($page.Url,
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
for($i=0; $i -lt $webpartmanager.WebParts.Count; $i++)
{
if($webpartmanager.WebParts[$i].GetType() -eq [ Microsoft.SharePoint.WebPartPages.ContentEditorWebPart])
{
$wp = $webpartmanager.WebParts[$i];
$wp.ChromeType=[System.Web.UI.WebControls.WebParts.PartChromeType]::TitleOnly;
$wp.Title="New Webpart"
$webpartmanager.SaveChanges($wp);
}
}
}
In here we’re checking whether the type of the web part is the Content Editor WP. In your case you will probably check for some other criteria as well as make updates to your own properties. To test the script – download and run it from here.
The script assumes – you’re in publishing environment and will ignore all of the collaboration sites.
Enjoy!