Powershell Script for Exchange MB Numbers Not Working

by allenr74 at 2012-10-30 07:35:16

I found the attached script online. It provides the number of mailboxes for a storage group. You need to provide the name of the mailbox server for it to work as it checks the server role.

I was using the cluster name and it was working just fine. Now it is now, even when I put in the name of the actual server. Can anyone determine why it is no longer working or suggest a more reliable script?

by DonJ at 2012-10-30 14:47:46
What does it do? "Did work, doesn’t now" isn’t much to work with.

I’m noting the use of -errorAction SilentlyContinue. Bad, as that suppresses error messages which might help you troubleshoot this. Consider removing those.
by allenr74 at 2012-10-31 12:48:05

It basically connects to the mailbox server and gathers the number of mailboxes in each storage group in a table format. This is done by running the script with -Server <servername>. The script then checks the server to make sure it is a valid mailbox server. The name I am using is a valid mailbox server but it seems to fail the role check. It did work when I first ran it, though.
by DonJ at 2012-10-31 12:53:08
Any error messages, after removing the ErrorAction parameters?
by allenr74 at 2012-11-02 07:39:18

Get-ExchangeServer : The operation could not be performed because object ‘SPUS0
01EXM01A’ could not be found on domain controller ‘spus001wdc01.domain.com’.

It is in active directory and DNS.
by DonJ at 2012-11-02 08:12:21
Well, that’s certainly a problem. It sounds like it’d be worth running Get-ExchangeServer manually, adding its -Verbose and -Debug switches in case they do something useful. Obviously something is up with it. However, I’m not enough of an Exchange expert to tell you what. But that’s the error you gotta solve to get the script working!
by trondhindenes at 2012-12-01 03:06:40
Allen, just out of curiosity: Which Exchange version are you on? If this is a 2010 environment you never reference the cluster name, always server name. (For Exchange 2007 I can’t remember, it’s been too long. But I think it’s the same there.)
by camlost at 2012-12-11 05:53:06
Get usage overview of databases on a specified Exchange server.

Name of an Exchange server (you want to specify a server with mailbox role).

Coeficient used to transform number into other units. Default value converts units to MiB.

Get-ExchangeDBSize.ps1 -Server "mboxServer"

[string]$Server = $env:COMPUTERNAME,
[int]$SizeCoef = 1048576

$dbs = Get-MailboxDatabase -Server $Server -ErrorAction "Stop" | Where-Object { !$_.Recovery } | Sort-Object Name
foreach ($db in $dbs) {
$mboxCount = 0
$mbox = Get-Mailbox -Database $db.Name -IgnoreDefaultScope -ResultSize unlimited
if ($mbox) {
$mboxCount = $mbox.Count

$path = "\$($db.Server){0}" -f ($db.EdbFilePath.Replace(":", "$"))
[long]$dbSize = (Get-ChildItem $path).Length / $SizeCoef

$props = @{
Database = $db.Name
Size = $dbSize
MboxCount = $mboxCount
$obj = New-Object PSObject -Property $props


This should work on E2010. I haven’t handled the exception thrown in case of bad server name because the default error message is self-descriptive.
EDIT: Requires PowerShell 2.0+.