I want read all the pages web part which is resides inside the site pages across site collection, sub site level. The code is below

$site = Get-SPSite 
# This is enough to select all webs in site collection, you don't need to select AllWebs
$webs = Get-SPWeb -Site $site -Limit ALL

# Iterate all webs
foreach ($web in $webs) {
    # Get SitePages library. If you have multiple libraries or use publishing,
    # you need to execute it for all libraries.
    $sitePages = $web.Lists.EnsureSitePagesLibrary()
    # This will only get files from root folder. You can use $folder.SubFolders to get all files
    $sitePages.RootFolder.Files | Select ServerRelativeUrl
$wpMngr = $SPweb.GetLimitedWebPartManager("",[System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared); #you could change the page
foreach($wp in $wpMngr.WebParts)
Write-Host "Title" $wp.Title
Write-Host "TypeName" $wp
Write-Host "content" $wp.Content.InnerText 
Write-Host "content Link" $wp.ContentLink                       
Write-Host "PartOrder" $wp.PartOrder
Write-Host  "Zone"    $wp.ZoneID
Write-Host "Id" $wp.Id
Write-Host "Zone Index" $wp.ZoneIndex
Write-Host "Image Link" $wp.ImageLink
Write-Host "Media Link" $wp.MediaLink

1 Answer 1


It seems you want to check the web parts used in the pages in your site pages library. As you are not quite familiar with the GetLimitedWebPartManager method, it may better to first use a script here: https://www.sharepointdiary.com/2015/08/find-all-web-parts-in-use-in-sharepoint-using-powershell.html

And here is a blog about how to use this method. https://thechriskent.com/tag/getlimitedwebpartmanager/

  • you saved me.. thank you for the links
    – Liz
    Jun 16, 2020 at 11:46
  • Along with this script i want to create log file which capture the errors.
    – Liz
    Jun 16, 2020 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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