Skip to content

Instantly share code, notes, and snippets.

@neilhoff
Created May 22, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neilhoff/d6b46ba0f25c1a08b1bb to your computer and use it in GitHub Desktop.
Save neilhoff/d6b46ba0f25c1a08b1bb to your computer and use it in GitHub Desktop.
SharePoint 2013: Get the size and content database for all site collections in a web application
# Iterate through all site collections in a SharePoint web application and output to a CSV file:
# - Site, Size(B), Size(MB), Size(GB), Content database
$webApp = 'http://webappurl'
$csvPath = 'e:\data.csv'
# Get all the sites in the web app
$sites = Get-SPWebApplication $webApp | Get-SPSite -Limit ALL
# Set the header for the file
$data = "Site, Size(B), Size(MB), Size(GB), Content Database"
# Loop through each site pulling the data needed appending to $data
Foreach($site in $sites){
$mb = "{0:F2}" -f($site.Usage.Storage/1024/1024)
$gb = "{0:F2}" -f($mb/1024)
$data += "`n" + $site.url + ", " + $site.Usage.Storage + ", " + $mb + ", " + $gb + ", " + $site.ContentDatabase.Name
}
# Output the data to the file
$data | out-file $csvPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment