Skip to content

Instantly share code, notes, and snippets.

@jcallaghan
Last active October 24, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcallaghan/34ca63ac81b84cf8d14a801f61d47d40 to your computer and use it in GitHub Desktop.
Save jcallaghan/34ca63ac81b84cf8d14a801f61d47d40 to your computer and use it in GitHub Desktop.
List all web parts that have been used on site pages in a given SharePoint Online site. Legacy approach.
# Connect to SPO (see seperate connect function - https://gist.github.com/jcallaghan/d61d4bd8d23fbadf9687434a0a49dd2d)
$context = Connect-SPO -url "https://tenant.sharepoint.com//"
# Get web
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
Write-Host "Processing web with URL: '$($web.Url)'"
# Get pages library
$list = $context.web.Lists.GetByTitle("Pages")
$context.Load($List)
$context.ExecuteQuery()
# Get files from pages library
$pages = $list.RootFolder.Files
$context.Load($pages)
$context.ExecuteQuery()
# Get particular page
$page = $pages | Where {$_.Name -eq "AllItems.aspx"}
$context.Load($page)
$context.ExecuteQuery()
# Get web part manager
$wpm = $page.GetLimitedWebPartManager([Microsoft.SharePoint.Client.WebParts.PersonalizationScope]::Shared)
$context.Load($wpm)
$context.ExecuteQuery()
# Get web parts
$webparts = $wpm.WebParts
$context.Load($WebParts)
$context.ExecuteQuery()
if($webparts.Count -gt 0){
Write-Host "Looping through all webparts..."
foreach($webpart in $webparts){
# Get web part properties
$wpProperties = $webpart.WebPart.Properties.FieldValues
write-host "Web Part: $($webpart.ID) $($wpProperties.Title)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment