This script collects the size of each Site Collection in a SharePoint farm. The values are written in a text file and are sorted in a descending order by Site Collection size. You may easily specify a different file path ($OutputPath) or file name ($OutputFileName) by modifying the corresponding variables.

Create a Windows Task Scheduler job on one of your SharePoint servers to readout the Site Collection sizes on a regular basis. You may change the retention time by changing the $RetentionTimeDays variable. The default value is 14 days.

# ----------------------------------------
# Author:   Roger Haueter [Microsoft MVP]
# Company:  isolutions AG
# ---------------------------------------
 
# Add SharePoint snap-in
Add-PSSnapin Microsoft.SharePoint.PowerShell

# Set variables
$OutputPath = "C:\SiteCollectionSize"
$OutputFileName = "SPSCsizes-$Today"
$OutputFile = "$OutputPath\$OutputFileName.txt"
$RetentionTimeDays = "14"
$Today = [string]::Format( "{0:yyyyMMdd}", [datetime]::Now.Date )

# Create output directory, if it doesn't exist
if(!(Test-Path -Path $OutputPath))
  {
   New-Item -ItemType Directory -Force -Path $OutputPath
  }

# Get Site Collection sizes and create output file
Get-SPSiteAdministration -Limit All | select Url, @{label="MB";Expression={[System.Math]::Round($_.DiskUsed/1MB, 0)}} | Sort-Object -Descending -Property "MB" | Format-Table –AutoSize | Out-File -FilePath $OutputFile

# Remove files older than x days
$Limit = (Get-Date).AddDays(-$RetentionTimeDays)
Get-ChildItem $OutputPath -Recurse | ? { -not $_.PSIsContainer -and $_.CreationTime -lt $Limit } | Remove-Item -Force