Archive

Posts Tagged ‘Automation’

Exchange Server 2013 Makes It Easier: Finding Database Storage Information

November 23rd, 2012 No comments

Q:Why a post on this, topic?

Ans:In few of my Exchange automation and reporting scripts I have to figure out storage statistics of databases such as total capacity, free space, free space percentage etc. And I find it more easier to discover such information in Exchange 2013.

In this post, I will show some sample Powershell snippets I used to get the statistics on Exchange 2010 and later we will see how to get the same information from Exchange 2013.

 

Finding Exchange 2010 Mailbox Database Storage Information:

Note: All below Cmdlets have to be executed from Exchange Management Shell.  If you use native powershell.exe and PSSession method without using Exchange Remoting module it may behave differently due to Deserialization.

Scenario 1: Database is hosted on a Lun/Disk with Drive Letter Assigned

 

1) Getting Database Details

$DB = "MBX-DB01"
$Database = Get-MailboxDatabase $DB
$DBServer = $Database.Server.Name
$DBLun = $Database.EdbFilePath.DriveName

 

2) Calling WMI to get the volume information

#Below cmdlet should be run in one line
$Lun = Get-WmiObject -Class WIn32_Volume -Filter "DriveLetter='$DBLun'" `
-ComputerName $DBServer -Property DriveLetter,Capacity,FreeSpace

3) Composing the useful information

$DiskName = $Lun.DriveLetter
 $DiskCapacity = [math]::round(($Lun.Capacity/1GB),2)
 $DiskFreeSpace = [math]::round(($Lun.FreeSpace/1GB),2)

In above two lines, we are converting the byte value to GB and rounding it to two decimal point

4) Finding Percentage of Free Space

$FreePercentValue = [math]::round(($DiskFreeSpace * 100 / $DiskCapacity),2)

Use above cmdlet if you want to further use the value for operations such as comparison or sorting.

Use below if your purpose is just to print or report, the difference is nothing but, in above method the actual value if it is 82.10 will be shown as 82.1 and in below method it will still show as 82.10 but the difference is below will give you a string value and you cannot do mathematical operations with strings.

$FreePercentage = "{0:N2}" -f $FreePercentValue

 

Scenario 2: Database is hosted on a Lun/Disk with MountPoint Access Path

1) Getting Database Information

 $DB = "MBX-DB02" $Database = Get-MailboxDatabase
 $DB $DBServer = $Database.Server.Name
 #We are not using drive letter here as there is no -
 #drive letter assigned to the volume.
 $DBLun = $Database.EdbFilePath.PathName

Now we have to make a correct calculation to refer to the mount point. The mounted folder information is stored in two properties of win32_volume instance. Those are Caption and Name.  But how do you know dynamically what is the mount volume path from just the complete path of a database, not possible.  Here you should know the importance of having standards for naming convention, if you have a unique naming convention for your Database Luns and Mount Volumes , you can use something like this. In my scenario the total length of the Mount Volume from the Edbfile path was 24. So I extract a substring to match with the mount volume. Secondly I am replacing every back slash with two backslash, this is not a must but if you are using WMI Query you need to provide two slashes and not one.

 

$DBLun = $DBLun.Substring(0,24)
$DBLun = $DBLun.Replace("\","\\")
$Lun = Get-WmiObject -Class WIn32_Volume -Filter "Name='$DBLun'" `
-ComputerName $DBServer -Property Name,Capacity,FreeSpace

There is no drive letter, so we record only the mounted volume path from the Name property.

$DiskName = $Lun.Name
$DiskCapacity = [math]::round(($Lun.Capacity/1GB),2)
$DiskFreeSpace = [math]::round(($Lun.FreeSpace/1GB),2)

 

Calculating Percentage Value

$FreePercentValue = [math]::round(($DiskFreeSpace * 100 / $DiskCapacity),2)
[string]$FreePercentage = "{0:N2}" -f $FreePercentValue

 

From above you can see, such a task would be not easy but manageable in a single on-premise or SMB environment. What about a large distributed enterprise or even in hosting environments. Here Exchange 2013 comes to rescue. You don’t have to make a single WMI call to get above described information. Everything is available from Exchange 2013 Mailbox Database Cmdlets.

 

A Quick look at Exchange 2013 Improvements in this Context:

I will try to show the changes by using the practical approach here. we will only explore the possibilities, it can be used in different ways according to your need.

$DB = "MBX-DB03"
$Database = Get-MailboxDatabase $DB
$DBServer = $Database.Server.Name
$DBCopyStatus = Get-MailboxDatabaseCopyStatus -identity $DB\$DBServer

 

Above you see I have used Get-MailboxDatabase cmdlet, which will give me the server name where the DB is currently mounted. Next I use Get-MailboxDatabaseCopyStatus cmdlet with -identity parameter in a form of DBName\ServerName – that is how a database copy is identified in DAG.

 

#Mountpoint or Drive Letter
$DBCopyStatus.DatabasePathIsOnMountedFolder
$DBCopyStatus.LogPathIsOnMountedFolder

 

The property DatabasePathIsOnMountedFolder and LogPathIsOnMOuntedFolder will tell you if the files are hosted on a Volume mounted to a folder or assigned with a drive letter. This is something very useful as to you no longer need to manually identify if the Database is using a mounted folder or  disk drive.

 

DatabaseVolumeMountPoint gives you the exact mounted folder or the drive letter

#DB Volume Mount Point or Drive Letter (Ends with "\" )
$DiskName = $DBCopyStatus.DatabaseVolumeMountPoint

 

LogVolumeMountPoint gives the Logs location

#Log Volume Mount Point or Drive Letter (Ends with "\" )
$DBCopyStatus.LogVolumeMountPoint

 

Surprisingly, you can even get the physical Disk Volume Name.

#Physical Disk Name
$DBCopyStatus.DatabaseVolumeName
$DBCopyStatus.LogVolumeName

 

Now lets collect other information we need for reporting or other automation scripts.

$DiskCapacity = $DBCopyStatus.DiskTotalSpace
$DiskFreeSpace = $DBCopyStatus.DiskFreeSpace
$DiskFreePercentage = $DBCopyStatus.DiskFreeSpacePercent

 

Unfortunately above three fields are only for DB Location, If you have DB and LOG on different LUN this cmdlet doesn’t give that ( at least as per my knowledge until I write this)

What I understand is most of the above information is added or useful for the new Autoreseed feature, and the three properties below as well.

 

#Properties relevant to Auto Reseed
$DBCopyStatus.LastDatabaseVolumeName
$DBCopyStatus.LastDatabaseVolumeNameTransitionTime
$DBCopyStatus.VolumeInfoError

 

Some information around the Numbers given by Exchange Cmdlet

DiskCapacity  and DiskFreeSpace are of  Microsoft.Exchange.Data.ByteQuantifiedSize Type, means which is a complete object with some methods and properties. So use Get-Member and look at it. By default the value is printed in a number + text format (a display friendly format) but that may not be what you always want to have.  there is a bit of calculation changes:

In My Lab Database:

!Assume DiskCapactiy is 26707226624 in Bytes.

$DiskCapacity.ToGB() will  give you 24

But if you do $DiskCapacity.ToBytes()  / 1GB will give you 24.87

For some calculations that .87 is not something you can avoid.

DiskFreeSpacePercentage is an integer (System.Int32) so nothing to worry there.

 

Few Tips:
 #Get a list of Active Database Copies on the currently connected server
 Get-MailboxDatabaseCopyStatus -Active
 #Get a list of All Active Database Copies on a particular server
 Get-MailboxDatabaseCopyStatus -Active -Server <ServerName>
 #To get some more useful Database Statistics `
 #Such as Physical size of the Database and `
 #AvailableNewMailboxSpace (This is not exactly the thing called whitespace) `
 #Below cmdlet is not new in Exchange 2013.
 Get-MailboxDatabase <DBName> -Status

I hope you got some insights, and this post was helpful.

I am happy to learn from you as well, please drop your feedback, comments, or suggestions in the comments area.

Enjoy Learning!