How to Get all webparts on sharepoint page using powershell

Here is 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://servername")

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
}
}
}
}