Get content database sizes for all web applications in a SharePoint farm using PowerShell

This PowerShell SharePoint tutorial explains, how to get content database size for all web applications in a sharepoint farm using PowerShell in SharePoint 2013/2016.

This script allows getting the size for all the content databases available in a SharePoint Farm. The script defines a function (Get-ContentDBSizes) that gets all the Web Applications existing in a SharePoint Farm. For each Web Application, the function also gets the information.

Get content database sizes for all web applications in a SharePoint farm using PowerShell

All you got to do is spin up PowerShell on any SharePoint server in the farm and run this:

#############################################################
# Script that gets content databases sizes for all the web applications in a SharePoint Farm
# Parameters: N/A
#############################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }
$host.Runspace.ThreadOptions = "ReuseThread"
#Function that gets the size of all the content databases
function Get-ContentDBSizes
{
try
{
$spWebApps = Get-SPWebApplication -IncludeCentralAdministration
foreach($spWebApp in $spWebApps)
{
#$spWebApp.Name
$ContentDatabases = $spWebApp. WSS_Content_Name (Change here DB name)
foreach($ContentDatabase in $ContentDatabases)
{
$ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2)
$ContentDatabaseInfo= $spWebApp.DisplayName + "," + $ContentDatabase.Name + "," + $ContentDatabaseSize + " GB"
$ContentDatabaseInfo
#Write-Host " * " $spWebApp.DisplayName "-" $ContentDatabase.Name ": " $ContentDatabaseSize " GB"
}
}
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
Get-ContentDBSizes > ContentDBs.csv
Stop-SPAssignment –Global
Remove-PsSnapin Microsoft.SharePoint.PowerShell

Once all modification done, Click on Run button on the PowerShell ISE. Like below:

get content database for site collection powershell
get content database for site collection powershell

After running successfully we will get result like below:

get content database size sharepoint 2013 powershell
get content database size sharepoint 2013 powershell

Open that .CSV file and verified all content DB size, below is the result sheet:

get content database size sharepoint 2016 powershell
get content database size sharepoint 2016 powershell

You may like following PowerShell SharePoint tutorials:

Hope this SharePoint PowerShell tutorial explains how to get content database sizes for all web applications in a SharePoint farm using PowerShell.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope
>