# Parameters
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$OutputPath = "C:\Temp\RecycleBinRpt.csv"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminCenterURL -Interactive
#Get All Site Collections
$SiteCollections = Get-PnPTenantSite -IncludeOneDriveSites:$false
$RecyclebinData = @()
$Counter = 1
#Loop through each site collection
ForEach($Site in $SiteCollections)
{
Try {
Write-host "Processing Site ($Counter of $($SiteCollections.count):" $Site.URL -f Yellow
#Connect to the site
Connect-PnPOnline -Url $Site.URL -Interactive
#Get Recycle bin Item Sizes
$FirstStageSize = Get-PnPRecycleBinItem -RowLimit 500000 -FirstStage | Measure-Object -Property Size -Sum
$SecondStageSize = Get-PnPRecycleBinItem -RowLimit 500000 -SecondStage | Measure-Object -Property Size -Sum
$FirstStageSizeInMB = [Math]::Round($FirstStageSize.Sum/1MB,2)
$SecondStageSizeInMB = [Math]::Round($SecondStageSize.Sum/1MB,2)
$TotalSize = $FirstStageSizeInMB+$SecondStageSizeInMB
#Collect Data
$RecyclebinData+= [PSCustomObject][ordered]@{
SiteName = $Site.Title
URL = $Site.URL
FirstStageSize = $FirstStageSizeInMB
SecondStageSize = $SecondStageSizeInMB
TotalSize = $TotalSize
}
$Counter++
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Export the data to CSV
$RecyclebinData | Format-Table
$RecyclebinData | Export-CSV -Path $OutputPath -NoTypeInformation
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}