SharePoint Content Databases Size – Storage Report using PowerShell

How to check SharePoint content database size?
To get the sizes of all your SharePoint content databases, use this PowerShell script:

Get-SPContentDatabase | foreach { $_.Name;[Math]::Round(($_.disksizerequired/1GB),2) }

Fairly simple! isn’t it? But every month I’ve had to generate the Storage report for SharePoint Content Databases. How about automating it with PowerShell? Sure, Here is my PowerShell script to get SharePoint content databases size.

Get SharePoint Content Database Size using PowerShell:

Lets get SharePoint content databases size, Export to a CSV and then Email using PowerShell.

#SharePoint Content Database Sizes - Storage Report
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

$ReportDate=get-date -Format "MMM-dd-yyyy"

$OutputFN = "D:\Database_Storage_$ReportDate.csv"

#If the File already exists remove it
if (Test-Path "D:\Database_Storage_$ReportDate.csv")
    Remove-Item "D:\Database_Storage_$ReportDate.csv"

#Write CSV Header
 Add-Content -Path $OutputFN -Value "Web Application Name, URL, Database Name, Database Size-GB"
#Get All Web Applications
$webapps = Get-SPWebApplication
foreach($webapp in $webapps)
    $ContentDatabases = $webapp.ContentDatabases
    foreach($ContentDatabase in $ContentDatabases)
        $ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2)

        Add-Content -Path $OutputFN " $($webapp.Name),  $($webapp.url) , $($ContentDatabase.Name) , $ContentDatabaseSize"

#Code To mail the Report
$SMTPClient = new-object System.Net.Mail.smtpClient
$ = ""

$MailMessage = new-object System.Net.Mail.MailMessage
$MailMessage.Subject = "SharePoint Storage Report - $ReportDate"
$MailMessage.Body = "Please find attached Database storage report as on $ReportDate"
$MailMessage.From = "[email protected]"
$MailMessage.To.add("[email protected]")
$Attachment = new-object System.Net.Mail.Attachment($OutputFN)


#Remove the Report from Server once mailed!
Remove-Item "D:\Database_Storage_$ReportDate.csv"

Output: (After adding a Pivot Table)

sharepoint content database size powershell

Tail: Once you have the script ready, You can place it under Task scheduler to run the script on scheduled basis! like: PowerShell.exe D:\Reports\StorageReport.ps1

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “SharePoint Content Databases Size – Storage Report using PowerShell

  • June 21, 2012 at 10:11 PM

    Hi, I am running this from my WFE and getting the email ok with attachment, but am getting an error message:
    “The term ‘Get-SPWebApplication’ is not recognized as the name of a cmdlet… ObjectNotFound: (Get-SPWebApplication:String)” in powershell. Do you have any suggestions?

    Running the cmd:
    PS D:SPReports> .contentdbstoragereport.ps1

    Thanks for looking

    • June 22, 2012 at 8:53 AM

      Are you trying to Run the script in MOSS 2007? Get-SPWebApplication will work only on SharePoint 2010! To use it in MOSS, Take a Look at Gary’s script:


Leave a Reply