Workloads/Get-SharePointUsage.ps1
|
# Get-SharePointUsage.ps1 # Collects 180-day SharePoint site activity via the Graph Reports API. # Part of the M365-QuickAssess module -- not exported. function Get-SharePointUsage { param ( $Assessment ) Write-Log "Collecting SharePoint activity data (180 days)" try { $sp = Get-GraphReportCsv ` -Uri "https://graph.microsoft.com/v1.0/reports/getSharePointSiteUsageDetail(period='D180')" if ( -not $sp -or $sp.Count -eq 0 ) { Write-Log "SharePoint activity report returned no data" "WARN" $Assessment.SharePoint.ActiveSiteCount = $null return } $activeCount = ( $sp | Where-Object { $_."Last Activity Date" } ).Count $inactiveCount = $sp.Count - $activeCount $Assessment.SharePoint.ActiveSiteCount = $activeCount Write-Log "SharePoint (180 days): Active=$activeCount Inactive=$inactiveCount" # ------------------------------------------------------------------- # Finding: High inactive site count # ------------------------------------------------------------------- if ( $sp.Count -gt 0 ) { $inactivePercent = [math]::Round( ( $inactiveCount / $sp.Count ) * 100, 0 ) if ( $inactivePercent -ge 40 ) { $Assessment.Findings += New-Finding ` -Type "HighInactiveSiteCount" ` -Summary "$inactiveCount SharePoint sites have had no activity in the last 180 days ($inactivePercent%)" ` -Category "SharePoint" ` -Severity "Medium" ` -Impact "A high number of inactive sites adds unnecessary storage and complexity to the migration." ` -Recommendation "Review inactive sites before migration and archive or delete as appropriate." } } } catch { Write-Log "SharePoint activity collection failed: $( $_.Exception.Message )" "ERROR" } } |