Get Content DataBase Size Using PowerShell in SharePoint 2013

get sharepoint content database size using powershell

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

Scenario:
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.
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

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= “+ $_.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

Hope this helps !!!

Similar SharePoint 2013 Tutorials


Leave a Reply