Quick Tip (Revisited) – How to get the physical sizes of Exchange Databases (in different versions of Exchange from a single script)

by Andy Grogan on October 28, 2012 · 0 comments

in Exchange 2007 (CCR), Exchange 2007 (General), Exchange 2010 (General), Exchange 2010 (Mailbox), Mailbox Databases, Quick Tips

A couple of weeks back I published a very simple script which I had been using on a few versions of Exchange to determine the physical sizes of each of the EDB files. A reader commented that in Exchange 2010 – such an elaborate script was not needed as the Get-MailboxDatabase cmdlet contains a “DatabaseSize” property which is populated from the Information Store on each mailbox server when the “–Size” parameter is used.

Bjarni Kristjansson

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

Of course Bjarni was correct – but his comment led me to consider how I had been using my original script. As I was familiar with the code and the environments that I was executing it within – I would modify it to essentially “work” when it stopped doing so – however, when I published a version of the the code on telnetport25.com – I discovered that what I produced was not all encompassing (or generic enough). Therefore;

  • Execution against Clustered 2007 Instances would not return any data
  • The script did not account for different versions of Exchange, and therefore did not use the most optimal command line syntax between 2007 and 2010

Given the above I have re-written the original script (and replaced the download with the new script) so that it will now:

  • Recognise the different syntax between the cmdlets required by Exchange 2010 and Exchange 2007
  • If the host environment is Exchange 2007, determine if the mailbox is hosted on a cluster or a basic Exchange instance and report on the physical database sizes

In order to work correctly in an Exchange 2007 environment the account in which the context of the script is run needs to have access to the hidden share at the root of each Exchange server (c$ for example).

Aside from the mail purpose of the script, there are some other learning points contained within its syntax – for example;

  • Exchange 2007 / 2010 – How to simply detect the major version of the Exchanger on a given server
  • Exchange 2007 CCR – How to determine the Active CCR node

The output of this script looks like the following depending on the version of Exchange that it executes against:

Exchange 2010

28-10-201213-11-07

Exchange 2007

28-10-201214-15-12

The (revised) Script

You can review the script below, or you can click on the download link provided in the Download section.

   1: <#

   2: .DESCRIPTION

   3:    Sample Script to demonstrate how you can get the physical Database Size for both Exchange 2007 and 2010

   4: .CREDITS & COPYRIGHT

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

   6:     Author: Andy Grogan

   7: .VERSION

   8:     2.0 - Revised Version

   9: #>

  10:

  11: function GetExchangeMajorVersion{

  12:     param(

  13:

  14:         $ExchangeServer

  15:

  16:     )

  17:     $SVR = Get-ExchangeServer $ExchangeServer

  18:

  19:     # Build a simple differentiation between Exchange 2007 and 2010

  20:

  21:     if($SVR.AdminDisplayVersion.Major -eq 8){

  22:         return "2007"

  23:

  24:     }elseif($SVR.AdminDisplayVersion.Major -eq 14){

  25:         return "2010"

  26:     }else{

  27:         Write-Host "This script is not supported on versions of Exchange prior to 2007" -ForegroundColor Red

  28:     }

  29:

  30: }

  31:

  32: function get_isACluster{

  33:     param ($Server)

  34:

  35:     $isCluster = Get-MailboxServer -Identity $Server | Select Name,ClusteredStorageType

  36:     if($isCluster.ClusteredStorageType -ne 'Disabled'){

  37:             return "Clustered"

  38:         }else{

  39:             return "notClustered"

  40:         }

  41: }

  42:

  43: function get_ActiveNode{

  44:     param(

  45:

  46:         $Server

  47:

  48:     )

  49:     $2007Cluster = Get-MailboxServer $Server

  50:     if($2007Cluster.ClusteredStorageType -ne "Disabled"){

  51:            $Stat = Get-ClusteredMailboxServerStatus $2007Cluster.Name | Select -Expand OperationalMachines | foreach {if($_ -like "*Active*") {$_}}

  52:            $AN = $Stat.Split(" ")[0]

  53:            return $AN

  54:     }

  55: }

  56:

  57: function get_DBSize2007Cluster{

  58:     param(

  59:         $Server, $DatabaseName

  60:     )

  61:         Write-Host "Working on Mailbox Database Server: " $Server -ForegroundColor "White"

  62:         $aNode = get_ActiveNode $Server

  63:         $thisDB = Get-MailboxDatabase -Identity $DatabaseName

  64:         Write-Host "Working against database: " $thisDB -ForegroundColor Green

  65:         Write-Host "Operational Cluster Node: " $aNode -ForegroundColor Yellow

  66:

  67:         $Path = "`\`\" + $aNode + "`\" + $thisDB.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $thisDB.EdbFilePath.PathName.Remove(0,2)

  68:         Write-Host $Path

  69:         $EdbFile = Get-ChildItem $Path

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

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

  72:         return $Result

  73:

  74: }

  75:

  76: function get_DBSize2007NONCluster{

  77:     param(

  78:         $Server

  79:     )

  80:         Write-Host "Working on Mailbox Database Server: " $Server -ForegroundColor "White"

  81:

  82:         $DBS = Get-MailboxDatabase -Server $Server

  83:

  84:         foreach($DB in $DBS){

  85:             Write-Host "Working against database: " $DB.Name -ForegroundColor "Green"

  86:             $Path = "`\`\" + $Server + "`\" + $DB.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $DB.EdbFilePath.PathName.Remove(0,2)

  87:             $EdbFile = Get-ChildItem $Path

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

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

  90:             return $Result

  91:         }

  92:

  93: }

  94:

  95: $Servers = Get-MailboxServer | Select -ExpandProperty Name

  96:

  97: foreach($Server in $Servers){

  98:      $result = GetExchangeMajorVersion $Server

  99:     if($result -eq "2007"){

 100:         $is2007Clustered = get_isACluster $Server

 101:         if($is2007Clustered -eq "Clustered"){

 102:             # Get databases paths of the databases on the cluster

 103:             $DatabasesONCluster = Get-MailboxDatabase -Server $Server | Select -expandProperty Identity

 104:             foreach($entry in $DatabasesONCluster){

 105:                 get_DBSize2007Cluster $Server "$entry"

 106:             }

 107:

 108:         }elseif($is2007Clustered -eq "notClustered"){

 109:             get_DBSize2007NONCluster $Server

 110:         }

 111:     }elseif($Result -eq "2010"){

 112:         Get-MailboxDatabase -server $Server -status | select ServerName,Name,DatabaseSize

 113:     }

 114: }

Download

You can download the scripts from the following location:

[ GetEXDBPhysicalSize.ps1 – 1.3KB ]

Execution of the script is as described in the original article.

{ 0 comments… add one now }

Leave a Comment

*

Previous post:

Next post: