Get-MailboxStatistics for Exchange 2003
Using PowerShell to create a version of Get-MailboxStatistics for Exchange 2003.
Get-MailboxStatistics returns a set of information about a mailbox for Exchange 2007. It is possible to retrieve roughly the same information using WMI for Exchange 2003.
The differences
The following table notes the differences in property names between Exchange 2003 and Exchange 2007.
| Exchange 2007 | Exchange 2003 |
|---|---|
| AssociatedItemCount | AssocContentCount |
| DeletedItemCount | Not available |
| DisconnectDate | DateDiscoveredAbsentInDS |
| DisplayName | MailboxDisplayName |
| ItemCount | TotalItems |
| ObjectClass | Can be assumed to be Mailbox |
| StorageLimitStatus | StorageLimitInfo |
| TotalDeletedItemSize | DeletedMessageSizeExtended |
| TotalItemSize | Size |
| Database | Composed of Server, Storage Group and Store |
| DatabaseName | StoreName |
| Identity | MailboxGuid (repeat of above included for pipeline) |
| IsValid | Not available |
| OriginatingServer | Same as ServerName |
In addition to these the MailboxGuid attribute is formatted slightly differently. The MailboxGuid is enclosed in curly braces, {}, these are stripped in the code (or added when a search is being performed using a GUID)
No formatting is applied to the output. The output from this function can be made to look like the Exchange 2007 version of Get-MailboxStatistics by using Format-Table.
Get-2003MailboxStatistics | Format-Table MailboxDisplayName, TotalItems, ` StorageLimitStatus, LastLogonTime
This is the code for the function, it is not as flexible as the Exchange 2007 version with regard to pipelines, but it should accept simple input and work in much the same way otherwise.
Usage examples
# With a Mailbox Display Name
Get-2003MailboxStatistics "Chris Dent"
# With a Legacy Exchange DN ("-Identity" itself is optional)
Get-2003MailboxStatistics -Identity "/O=SomeOrg/OU=AdminGroup/CN=RECIPIENTS/CN=Someone"
# For a single Mailbox Database
Get-2003MailboxStatistics -Database "Mailbox Database"
# For a different server
Get-2003MailboxStatistics -Server "ExchangeServer02"
Get-MailboxStatistics for Exchange 2003
Function Get-2003MailboxStatistics {
Param(
[String]$Identity = "",
[String]$Server = $Env:ComputerName,
[String]$Database = ""
)
$Filter = "ServerName='$Server'"
if ($Database -ne "" ) {
$Filter = "$Filter AND StoreName='$Database'"
}
if ($Identity -ne "") {
$Filter = "$Filter AND (MailboxGuid='{$Identity}' OR LegacyDN='$Identity'"
$Filter = "$Filter OR MailboxDisplayName='$Identity')"
}
Get-WMIObject -ComputerName $Server `
-Namespace "root/MicrosoftExchangeV2" -Class "Exchange_Mailbox" `
-Filter $Filter | `
Select-Object `
AssocContentCount, `
@{n='DateDiscoveredAbsentInDs';e={
If ($_.DateDiscoveredAbsentInDs -ne $Null) {
[Management.ManagementDateTimeConverter]::ToDateTime(`
$_.DateDiscoveredAbsentInDs)
}} }, `
MailboxDisplayName, TotalItems, LastLoggedOnUserAccount, `
@{n='LastLogonTime';e={ if ($_.LastLogonTime -ne $Null) { `
[Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogonTime)}}
}, `
@{n='LastLogoffTime';e={ if ($_.LastLogoffTime -ne $Null) { `
[Management.ManagementDateTimeConverter]::ToDateTime($_.LastLogoffTime)}}
}, `
LegacyDN, `
@{n='MailboxGuid';e={
([String]$_.MailboxGuid).ToLower() -Replace "\{|\}" }}, `
@{n='ObjectClass';e={ "Mailbox" }}, `
@{n='StorageLimitStatus';e={ `
Switch ($_.StorageLimitInfo) {
1 { "BelowLimit" }
2 { "IssueWarning" }
4 { "ProhibitSend" }
8 { "NoChecking" }
16 { "MailboxDisabled" } }} }, `
DeletedMessageSize, Size, `
@{n='Database';e={
"$($_.ServerName)\$($_.StorageGroupName)\$($_.StoreName)" }}, `
ServerName, StorageGroupName, StoreName, `
@{n='Identity';e={ ([String]$_.MailboxGuid).ToLower() -Replace "\{|\}" }}
}
Related posts:
- Changing the Primary Group with PowerShell Exactly as the title says, an example of how to...
Related posts brought to you by Yet Another Related Posts Plugin.
Posted by Nathan on 22.01.09 at 5:35 pm
Thanks! I was looking for pretty much this exact script; this saved me a LOT of time in writing it. One observation; the “-Database” switch was causing it to fail, until I made a change. On line 10 I changed:
$Filter = “$Filter AND StoreName=’$Database ($Server)’”
to:
$Filter = “$Filter AND StoreName=’$Database’”
That’s all it took in my environment (Exchange 2003 SP2 on Server 2003 Enterprise 32 bit.)
Posted by Chris on 22.01.09 at 5:35 pm
Thanks for that, overlooked the default naming for stores on my installation of 2003.
Chris
Posted by TonyRoZe on 22.01.09 at 5:35 pm
No matter what switch I use the script just returns me to the cmd promp without displaying any data. What am I doing wrong ?
Posted by Chris on 22.01.09 at 5:35 pm
Try running with no switches, assuming you’re running from the Exchange server itself? Or just run this on its own:
Get-WMIObject -ComputerName “YourServer” -Namespace “root/MicrosoftExchangeV2″ -Class “Exchange_Mailbox”
If that returns nothing then neither will my script.
Chris
Posted by TonyRoZe on 22.01.09 at 5:35 pm
the Query Above works just fine and I was able to get your script to function after removing the following section (only -server functions which meets my needs)
$Filter = “ServerName=’$Server’”
if ($Database -ne “” ) {
$Filter = “$Filter AND StoreName=’$Database’”
}
if ($Identity -ne “”) {
$Filter = “$Filter AND (MailboxGuid=’{$Identity}’ OR LegacyDN=’$Identity’”
$Filter = “$Filter OR MailboxDisplayName=’$Identity’)”
}
Posted by blake on 22.01.09 at 5:35 pm
excellent work, thanks
Posted by Derek on 22.01.09 at 5:35 pm
Very much appreciated.