How to loop through all the pages in site pages
-
08-02-2021 - |
Domanda
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
$listItemData=@()
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
}
Soluzione
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/
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange