Monitoring SharePoint site usage helps track user activity, storage consumption, and file interactions. Using PnP PowerShell, you can generate detailed site usage reports and export them to CSV for analysis.
Step 1: Install and Connect PnP PowerShell
Ensure PnP PowerShell is installed and connected to your SharePoint tenant:
Install-Module -Name PnP.PowerShell -Scope CurrentUser -Force
Connect to SharePoint Online:
$SiteUrl = "https://yourtenant.sharepoint.com/sites/Reports"
Connect-PnPOnline -Url $SiteUrl -Interactive
Connected to SharePoint Online!
Step 2: Retrieve Site Usage Details
You can fetch key site usage metrics such as storage size, number of files, and active users.
$SiteUsage = Get-PnPTenantSite -Url $SiteUrl
Write-Host "Site Title: $($SiteUsage.Title)"
Write-Host "Storage Used (MB): $($SiteUsage.StorageUsageCurrent)"
Write-Host "Last Content Modified: $($SiteUsage.LastContentModifiedDate)"
Basic site usage details retrieved!
Step 3: Fetch Detailed Site Activity Reports
To get site activity details such as file views, page visits, and active users, use:
$Report = Get-PnPGraphReport -Name "SharePointSiteUsageDetail" -Period D30
$Report | Format-Table SiteId, SiteURL, OwnerDisplayName, StorageUsedMB, FileViews, ActiveUsers -AutoSize
Site activity report generated!
Step 4: Export Site Usage Report to CSV
To analyze data later, export the report to a CSV file:
$Report | Export-Csv -Path "C:\Reports\SiteUsageReport.csv" -NoTypeInformation
Write-Host "Site usage report exported successfully!"
Report saved as CSV!
Step 5: Automate Report Generation with Scheduled Task
To automate report generation daily, use Task Scheduler:
1️⃣ Create a PowerShell script (SiteUsageReport.ps1):
$SiteUrl = "https://yourtenant.sharepoint.com/sites/Reports"
Connect-PnPOnline -Url $SiteUrl -Interactive
$Report = Get-PnPGraphReport -Name "SharePointSiteUsageDetail" -Period D30
$Report | Export-Csv -Path "C:\Reports\SiteUsageReport.csv" -NoTypeInformation
2️⃣ Open Task Scheduler → Create Basic Task
3️⃣ Set trigger to Daily
4️⃣ Set action to Start a program → Browse and select powershell.exe
5️⃣ Add argument:
-File "C:\Scripts\SiteUsageReport.ps1"
Automated daily site usage reports!
Step 6: Retrieve Storage Reports for All Sites
To list storage usage for all sites in your tenant:
$Sites = Get-PnPTenantSite
$Sites | Select Title, Url, StorageUsageCurrent | Export-Csv -Path "C:\Reports\AllSitesStorage.csv" -NoTypeInformation
Storage report for all sites generated!