Get Site Collection Size with PowerShell
Working with a customer recently I was asked to write a PowerShell script to get the site collection size per content database. The script is pretty quick to run typically and can give an added benefit of allowing you to track growth over time if you don't remove the file from the server.
Add-PSSnapin microsoft.sharepoint.powershell
$SizeLog = "D:\temp\SPSiteSize.csv"
############################################################
$CurrentDate = Get-Date -format d
$WebApps = Get-SPWebApplication
foreach($WebApp in $WebApps)
{
$Sites = Get-SPSite -WebApplication $WebApp -Limit All
foreach($Site in $Sites)
{
$SizeInKB = $Site.Usage.Storage
$SizeInGB = $SizeInKB/1024/1024/1024
$SizeInGB = [math]::Round($SizeInGB,2)
$CSVOutput = $Site.RootWeb.Title + "*" + $Site.URL + "*" + $Site.ContentDatabase.Name + "*" + $SizeInGB + "*" + $CurrentDate
$CSVOutput | Out-File $SizeLog -Append
}
}
$Site.Dispose()
Comments
- Anonymous
December 03, 2015
This worked great for me. Thanks for posting this!