Updating SharePoint Web Parts

From Secrets of SharePoint – Tip of the Day

You can use Windows PowerShell when updating Web Parts on a SharePoint 2010 Web site. First, you can retrieve a specific Web site:

PS > $spWeb = Get-SPWeb http://SP01.powershell.nu

Next, retrieve the Site page that contains the Web Part and check it out:

PS > $sitePages = $spWeb.GetFolder(“SitePages”)

PS > $homeASPX = $sitePages.Files |

>> Where-Object { $_.Name -eq “Home.aspx” }

PS > $homeASPX.CheckOut()

Next, retrieve the Web Part Collection using the GetWebPartCollection() method:

PS > $webPartCollection =

>> $spWeb.GetWebPartCollection(“SitePages/Home.aspx”,”Shared”)

Next, retrieve a Web Part from the Web Part Collection. In this example, we’ll use the “Shared Documents” Web part on a Default Team Site:

PS > $webPart = $webPartCollection |

>> Where-Object { $_.Title -eq “Shared Documents” }

Now, you can update various properties on the Web Part. In the example below, you can change the Web Part’s title:

PS > $webPart.Title = “A New Title”

To save the changes, you can use the SaveChanges() method on the Web Part Collection and check in the Site Page:

PS > $webPartCollection.SaveChanges($webPart.StorageKey)

PS > $homeASPX.CheckIn(“”)

PS > $homeASPX.Publish(“”)

About Rick Backus

A technology consultant with over 25 years of IT, consulting and business technology industry experience. Specializing in integrating application, information and content management with business process and network infrastructure. Helping clients get the most out of technology to enable increased productivity, profitability, customer satisfaction and competitive advantage.

Leave a Reply