Monitoring SharePoint Online site performance is crucial for ensuring:
Fast page load times
Optimized storage & query performance
Efficient resource utilization
Early detection of performance issues
Using PnP PowerShell, we can automate site performance monitoring by analyzing:
🔹 Page load times
🔹 Storage & quota usage
🔹 Site response times
🔹 Search performance
🔹 Large lists & libraries
Step 1: Connect to SharePoint Online
To start, authenticate with SharePoint Online:
$adminUrl = "https://yourtenant-admin.sharepoint.com"
Connect-PnPOnline -Url $adminUrl -Interactive
Write-Host " Connected to SharePoint Online Admin Center"
✔ Ensures secure access to SharePoint.
Step 2: Retrieve All SharePoint Sites
Get all SharePoint Online site collections:
$allSites = Get-PnPTenantSite
Write-Host " Total SharePoint Sites: $($allSites.Count)"
✔ Fetches a list of all sites for performance analysis.
Step 3: Measure Page Load Time
Check how long a site takes to load:
$siteLoadTimes = @()
foreach ($site in $allSites) {
$startTime = Get-Date
Invoke-WebRequest -Uri $site.Url -UseBasicParsing | Out-Null
$endTime = Get-Date
$loadTime = ($endTime - $startTime).TotalSeconds
$siteLoadTimes += [PSCustomObject]@{
SiteURL = $site.Url
LoadTimeS = $loadTime
Status = if ($loadTime -gt 3) { " Slow" } else { " Fast" }
}
}
$siteLoadTimes | Format-Table -AutoSize
✔ Identifies slow-loading sites.
Step 4: Monitor Storage & Quota Usage
Track storage consumption for each site:
$storageReport = @()
foreach ($site in $allSites) {
$storageUsedMB = [math]::Round($site.StorageUsageCurrent / 1024, 2)
$storageLimitMB = [math]::Round($site.StorageMaximumLevel / 1024, 2)
$storageReport += [PSCustomObject]@{
SiteURL = $site.Url
StorageUsedMB = $storageUsedMB
StorageLimitMB = $storageLimitMB
Status = if ($storageUsedMB -gt ($storageLimitMB * 0.9)) { "⚠️ Near Limit" } else { " Healthy" }
}
}
$storageReport | Format-Table -AutoSize
✔ Helps prevent storage issues.
Step 5: Identify Large Lists & Libraries
Find lists with 5,000+ items (SharePoint list view threshold issue):
$largeLists = @()
foreach ($site in $allSites) {
$lists = Get-PnPList -Web $site.Url
foreach ($list in $lists) {
if ($list.ItemCount -gt 5000) {
$largeLists += [PSCustomObject]@{
SiteURL = $site.Url
ListName = $list.Title
Items = $list.ItemCount
Status = " Large List"
}
}
}
}
$largeLists | Format-Table -AutoSize
✔ Identifies potential list performance issues.
Step 6: Check Search Performance
Monitor SharePoint Search Response Time:
$searchTimes = @()
foreach ($site in $allSites) {
$startTime = Get-Date
Get-PnPSearchQueryResults -Query "SharePoint" -All | Out-Null
$endTime = Get-Date
$searchTime = ($endTime - $startTime).TotalSeconds
$searchTimes += [PSCustomObject]@{
SiteURL = $site.Url
SearchTimeS = $searchTime
Status = if ($searchTime -gt 2) { "⚠️ Slow" } else { "✅ Fast" }
}
}
$searchTimes | Format-Table -AutoSize
✔ Detects slow search queries.
Step 7: Generate a CSV Report
Compile all findings into a CSV file:
$reportData = @()
foreach ($site in $allSites) {
$reportData += [PSCustomObject]@{
SiteURL = $site.Url
LoadTimeS = ($siteLoadTimes | Where-Object { $_.SiteURL -eq $site.Url }).LoadTimeS
StorageUsedMB = ($storageReport | Where-Object { $_.SiteURL -eq $site.Url }).StorageUsedMB
LargeLists = ($largeLists | Where-Object { $_.SiteURL -eq $site.Url }).Count
SearchTimeS = ($searchTimes | Where-Object { $_.SiteURL -eq $site.Url }).SearchTimeS
}
}
$reportPath = "C:\Reports\SharePointPerformanceReport.csv"
$reportData | Export-Csv -Path $reportPath -NoTypeInformation
Write-Host " Performance Report Generated: $reportPath"
✔ Provides actionable insights.
Step 8: Automate the Report
Schedule the script to run weekly using Task Scheduler:
$taskAction = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\MonitorPerformance.ps1"
$taskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 2AM
Register-ScheduledTask -TaskName "SharePoint Performance Monitoring" -Action $taskAction -Trigger $taskTrigger -RunLevel Highest
✔ Ensures continuous performance tracking.