Get Content DataBase Size Using PowerShell in SharePoint 2013

This PowerShell SharePoint 2013 tutorial explains, how to get content database size using PowerShell in SharePoint 2013. The same PowerShell script we can use to get content database size using PowerShell in SharePoint 2016.

Scenario:
While migrating SharePoint one version to another 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.

  • The first script will provide 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.
  • 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.

SharePoint 2013 get content database size using PowerShell Script

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

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.
https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/Get-SPDatabase?view=sharepoint-ps

“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

Get Content DataBase Size Using PowerShell in SharePoint 2013

This PowerShell 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= “+ $_.name} {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

You may like following SharePoint PowerShell tutorials:

Hope this PowerShell script helps to retrieve SharePoint content database size using PowerShell in SharePoint 2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>