October 13, 2012

Quick Tip – How can I get the physical sizes of all my Exchange databases

I have been doing some work recently on pulling capacity management information from Exchange 2010 using PowerShell. One requirement that I needed to satisfy was returning the physical size of all Exchange Database files within the organisation. There are a number of examples of how this can be done when you have a look around the Internet – however I found them (personally) to be a bit complex – or part of a wider script that can be hard to extract what you need from.

So I decided write my own version which can be modified to accommodate your own purposes.

The following script is a slightly modified version what I came up with for my capacity management assignment:

   1: <#


   3:    Sample Script to demonstrate how you can get the physical Database Size


   5:     2012 (c) Telnetport25.com - Released under the GNU version 3.0

   6:     Author: Andy Grogan

   7: #>


   9: Get-PSSnapin Microsoft.Exchange.* -Registered -ErrorAction SilentlyContinue | Out-Null

  10: if(!$?){

  11:     Write-Host "The Exchange Management Admin Tools are not installed on this server." -ForegroundColor Red

  12:     exit(1)

  13: }else{

  14:     Write-Host "The Exchange Management Tools are installed." -ForegroundColor Green

  15: }


  17: function get_DBSize{

  18:     param(

  19:         $DB

  20:     )

  21:     $DBnfo = Get-Mailboxdatabase -Identity $DB | Select-Object Name,Server,EDBFilePath

  22:     foreach($MBXDB in $DBnfo){


  24:         $server = $MBXDB.Server

  25:         $Path ="`\`\" + $server + "`\" + $MBXDB.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $MBXDB.EdbFilePath.PathName.Remove(0,2)

  26:         $EdbFile = Get-ChildItem $Path

  27:         $DBSize = $EdbFile.length / 1GB

  28:         $Result = [Math]::Round($DBSize,2)

  29:         return $Result

  30:     }

  31: }


  33: $MailboxDatabases = Get-MailboxDatabase | Select -ExpandProperty Name


  35: foreach($mbxDB in $MailboxDatabases){


  37:     $returnedSizes = get_DBSize $mbxDB


  39:     foreach($sizeEntry in $returnedSizes){

  40:         Write-Host "Mailbox Database: " $mbxDB -ForegroundColor Yellow

  41:         Write-Host "Size: " $sizeEntry "GB" -ForegroundColor Cyan

  42:     }


  44: }

Using the script

You can download the script above from the following location:

[ GetEXDBPhysicalSize.ps1 – 1.3KB ]

You should execute the script from an Exchange Server in your Infrastructure using the guidance that I have provided here: http://www.telnetport25.com/2012/02/quick-tip-running-exchange-based-powershell-script-files-from-the-command-line-or-a-batch-file/

Example Output

Successful execution of the script will produce output similar to that below.


The script is provided free for you to modify / use how you see fit – there are many modifications that can be made – for example:

  • Port the output to HTML
  • E-Mail the sizes to an administrator
Exchange 2010 Articles, Powershell 2 Replies to “Quick Tip – How can I get the physical sizes of all my Exchange databases”
Andy Grogan
Andy Grogan


2 thoughts on “Quick Tip – How can I get the physical sizes of all my Exchange databases

    Author’s gravatar

    Or this one liner… Get-MailboxDatabase -server servername -status | select ServerName,Name,DatabaseSize
    Rgds. BK

      Author’s gravatar

      Hi Bjarni, you are of course correct. I will be providing an updated version of the script which works for both Exchange 2007 (including clustered instances). When I wrote it the other day – I was still thinking about 2007, neglecting the Database size property.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do NOT follow this link or you will be banned from the site!
%d bloggers like this: