# 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