EnjoySharePoint YouTube Channel

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

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.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

PowerShell script 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}}

Read: PowerShell SharePoint Examples

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

[code]

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

[/code]

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

Get Content database size using SharePoint server object model

Below code you can use to get content database size:

[code]

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();

[/code]

Read: 15+ SharePoint server object model examples

Hope this will be helpful to get content database size using PowerShell in SharePoint 2016 and using SharePoint server object model.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint 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 →