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

sharepoint-2013-powershell-content-database-size
InfoPath alternatives for form designing SharePoint

In this post we will disucss how we can get content database size for all web applications in a sharepoint farm using PowerShell in SharePoint 2013. This scripts allows to get 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

Read some SharePoint tutorials

Comparing SharePoint 2016 Boundaries and limitations with SharePoint 2013 and SharePoint 2010

SharePoint server 2016 new and removed features

Get all SharePoint Users in CSV File from Farm using PowerShell in SharePoint

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 size powershell
get content database size powershell

After running successfully we will get result like below:

get content database size sharepoint 2010 powershell
get content database size sharepoint 2010 powershell

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

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

Hope this will be helpful.

Similar SharePoint 2013 Tutorials


Leave a Reply