Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Friday, December 02, 2011

Powershell script for getting all the webparts in a SharePoint Page


[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

[System.Reflection.Assembly]::LoadWithPartialName(“System.Xml”)

$webApp=[Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(“http://servernam
e”)

foreach($site in $webApp.Sites)

{

$web=$site.RootWeb

$file=$web.GetFile(“MyWebPartPage.aspx”)

if($file.Exists)

{

$wpManager=$web.GetLimitedWebPartManager(“Default.aspx”,[System.Web.UI.WebControls
.WebParts.PersonalizationScope]::Shared)

foreach($webPart in $wpManager.WebParts)

{

if($webPart.GetType().Name -eq “myContentEditorWebPart”) -> Getting my ContentEditor
WebPart.

{

$wp=[MicroSoft.SharePoint.WebPartPages.ContentEditorWebPart]$webPart
}
}
}
}

No comments:

Post a Comment