How to get content database size using PowerShell in SharePoint 2016 and using SharePoint server object model

How to get content database size using PowerShell in SharePoint 2016 and using SharePoint server object model
InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can retrieve SharePoint 2016 content database size using PowerShell and using SharePoint 2016 server object model. If you are new to SharePoint 2016, you can check installation steps of SharePoint 2016 and SharePoint 2016 new and improved features and SharePoint 2016 List View Auto Indexing Automatic Index Management.

PowerShell to retrieve content database size:
Below is the PowerShell command.
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, @{Label =”Size in MB”; Expression = {$_.disksizerequired/1024/1024}}

If you want to download in csv or .txt format, they you can write code like below:

How to get content database size using PowerShell in SharePoint 2016 and using SharePoint server object model
How to get content database size using PowerShell in SharePoint 2016 and using SharePoint server object model

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, @{Label =”Size in MB”; Expression = {$_.disksizerequired/1024/1024}} >E:\Content_DBsize.csv

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-Table Name, @{Label =”Size in MB”; Expression = {$_.disksizerequired/1024/1024}} >E:\Content_DBsize.txt

Once you run the command, this will display like below:

Get Content database size using server object model:

Below code you can use to get content database size:

string s = string.Empty;

using (SPSite startSite = new SPSite(“http://mypc:29024/sites/SPTraining/”))

{

SPFarm farm = startSite.WebApplication.Farm;

SPWebService service = farm.Services.GetValue<SPWebService>(“”);

foreach (SPWebApplication webApplication in service.WebApplications)

{

foreach (SPContentDatabase contentdatabase in webApplication.ContentDatabases)

{

s += “Name: ” + contentdatabase.Name + “Size: ” + contentdatabase.DiskSizeRequired/(1024*1024)+” MB”+ “\n”;

}

}

}

label11.Text = s.ToString();

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply