PowerShell Get site collection disk size

#Large amounts of memory are often required when SPWeb, SPSite, or SPSiteAdminsitration objects are used. So the use of these objects, or lists of these objects,
#in Windows PowerShell scripts requires proper memory management. By default, all Get commands dispose of these objects immediately after the pipeline finishes,
#but by using SPAssignment, you can assign the list of objects to a variable and dispose of the objects after they are no longer needed. You can also ensure that
#the objects remain as long as you need them, even throughout multiple iterations of commands.

# The amount of disk space that is displayed does not include the disk space used by the auditing data that will be moved with the site collection.
# ref https://technet.microsoft.com/en-us/library/ee125874(v=office.14).aspx

clear
Start-SPAssignment -Global
$SiteUrl = “http://yourdomain/sitename”
$diskSizeBytes = (Get-SPSiteAdministration -Identity $SiteUrl).DiskUsed
$diskSizeMB = ($diskSizeBytes/1024)/1024
$diskSizeGB = ($diskSizeMB/1024)

write-host $SiteUrl “–>” ([math]::Round($diskSizeGB,2))  “GB”
Stop-SPAssignment -global

Leave a Reply

Your email address will not be published. Required fields are marked *