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

by Andy Grogan on October 13, 2012 · 2 comments

in Exchange 2010 (General), Mailbox Databases, Powershell, Quick Tips

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: <#

   2: .DESCRIPTION

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

   4: .CREDITS & COPYRIGHT

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

   6:     Author: Andy Grogan

   7: #>

   8:

   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: }

  16:

  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){

  23:

  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: }

  32:

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

  34:

  35: foreach($mbxDB in $MailboxDatabases){

  36:

  37:     $returnedSizes = get_DBSize $mbxDB

  38:

  39:     foreach($sizeEntry in $returnedSizes){

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

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

  42:     }

  43:

  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.

13-10-201215-35-07

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

{ 2 comments… read them below or add one }

Bjarni Kristjansson October 13, 2012 at 10:05 pm

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

Reply

Andy Grogan October 14, 2012 at 2:51 pm

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.
Cheers
A

Reply

Leave a Comment

*

Previous post:

Next post: