Skip to content

Instantly share code, notes, and snippets.

@neilhoff
Created May 22, 2015 14:24
Show Gist options
  • Save neilhoff/d6b46ba0f25c1a08b1bb to your computer and use it in GitHub Desktop.
Save neilhoff/d6b46ba0f25c1a08b1bb to your computer and use it in GitHub Desktop.

Revisions

  1. neilhoff created this gist May 22, 2015.
    21 changes: 21 additions & 0 deletions GetSiteCollectionSizeAndLocation.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # 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