How to Identify the Size of the Content Database using PowerShell in SharePoint 2013


Sathish Nadarajan
SharePoint MVP
Published On :   12 Jan 2015
Visit Count
Today :  4    Total :   15524
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!


Recently I came across a requirement like retrieving the Content DB Size of a WebApplication using PowerShell. The WebApplication may have many Content DBs. So, all the Content DBs needs to be listed and their corresponding sizes needs to be exported into an Excel as output.

Thought of Sharing to the community.

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 
 $LogFile = ".\ContentDBSize-$LogTime.rtf"
 
 #cls
 
 ##================================================================================================
 
 ## Description : Get the Content DBs and their Sizes
 
 ## Author : Sathish Nadarajan
 
 ## Date : 09-Jan-2015
 
 ##================================================================================================
 
 $Host.UI.RawUI.WindowTitle = "-- Get Content DBs Size --"
 
 $StartDate = Get-Date
 
 Write-Host -ForegroundColor White "------------------------------------"
 
 Write-Host -ForegroundColor White "| Get Content DBs Size |"
 
 Write-Host -ForegroundColor White "| Started on: $StartDate |"
 
 Write-Host -ForegroundColor White "------------------------------------"
 
 #start-transcript $logfile
 
 ################################################### Add SharePoint PowerShell Snapin ######################################
 
 if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
 
 Add-PSSnapin Microsoft.SharePoint.Powershell
 
 }
 
 ########################################################### End of PowerShell Snapin ########################################
 
 ########################################################### Set the Exxecution Path #########################################
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 
 Set-Location $scriptBase
 
 ########################################################### End of Set the Exxecution Path ##################################
 
 ########################################################### Prepare the Output File with Header #############################
 
 $Output = $scriptBase + "\" + "ContentDBInfo.csv";
 
 "WebApplication" + "," + "ContentDBName" + "," + "Size in MB" | Out-File -Encoding Default -FilePath $Output;
 
 ############################################### End of Prepare the Output File with Header ##################################
 
 $webApplication = Read-Host "Please enter the WebApplication URL"
 
 $contentDataBases = Get-SPContentDatabase -webapplication $webApplication
 
 Write-Host "The Count of Content Databases for the WebApplication is :- " $contentDataBases.Count -ForegroundColor Green
 
 if($contentDataBases.Count -ne $null)
 
 {
 
 for($i=0; $i -le $contentDataBases.Count-1; $i++)
 
 {
 
 Write-Host $contentDataBases[$i].Name
 
 $contentDataBase = Get-SPDatabase | where-object { $_.Name -eq $contentDataBases[$i].Name }
 
 $webApplication + "," + $contentDataBase.Name + "," + $contentDataBase.disksizerequired/1024/1024 | Out-File -Encoding Default -Append -FilePath $Output;
 
 }
 
 }
 

Happy Coding.

Sathish Nadarajan.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Scan