Get Content DataBase Size Using PowerShell in SharePoint 2013

get sharepoint content database size using powershell
InfoPath alternatives for form designing SharePoint

Here we will discuss how to get content database size using PowerShell in SharePoint 2013.

While migrating SharePoint one version to other version we need to know the content DB sizes and total disk space to be required to on new SQL server.

In this article I would like to walk you through 2 PowerShell scripts.

1. The first script will provide the all the content databases created / associated with the application server in: Size of the DB in GB and the content Databases name in a tabular format.
2. The second script will provide all the content database sizes along with the total space required on the new SQL Server to be migrated on.

You can use Visual studio code to run, debug and test PowerShell script.

Script 1:

The below script will get all the content databases names and its size in GB with a tab separation.

Get-SPDatabase | Sort-Object disksizerequired –desc | %{write-hist “`nSize:” (“{0:N2}”-f $($_.disksizerequired/1024mb)) GB “`tDatabase; $($_.Name)”}

This will provide the output as below:

get content database size using powershell
get content database size using powershell

“Get-SPDatabase” is to get all the list of content databases associated with the application server.

“Sort-Object disksizerequired –desc” this is to sort the list with the size of content DB in descending order.

“`n” this character is to create a new line for every content DB

“{0:N2}” –f this helps to format the DB size with 2 decimals. For more formatting options please see the Technical article.

$_.diskspacerequired/1024mbdetermining the size of the content DB and dividing it with 1024 mb which will eventually return the size in GB

Script 2:

This script will read through each and every content database created / associated with the application server with the help of a foreach loop and sum-up the total size.

Get-SPDatabase | ForEach-Object {$db=0} {$db+=$_.disksizerequired; “`nDB Size =”+ (“{0:N2}” – f ($_.disksizerequired/1024mb)) + “ GB `t`t Content Database= “+ $} {Write-Host “`n Total Storage Space Required=” (“{0:N2}” –f ($db/1024mb)) GB}

This will provide the below output:

get sharepoint content database size using powershell
get sharepoint content database size using powershell

Hope this helps !!!

Similar SharePoint 2013 Tutorials

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 12 years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019

View all posts by Krishna Vandanapu →

Leave a Reply