For an Exchange administrator there are a lot of different situations in which they may need to know how many mailboxes are in the organization. Fortunately this is made easy in Exchange Server 2010 with a few simple PowerShell commands.
To get a count of all mailboxes in the Exchange 2010 organization use the following command:
[PS] C:\>(Get-Mailbox).count 393
Note that if you know your organization has over 1000 mailboxes you need to make sure that the result size of the command output is not limited.
[PS] C:\>(Get-Mailbox -resultsize unlimited).count 393
Next, we can get a count of mailboxes per Exchange 2010 mailbox server.
[PS] C:\>Get-Mailbox | Group-Object -Property:ServerName | Select-Object name,count Name Count ---- ----- esp-br-ex2010 23 esp-ho-ex2010b 370
We can also get a count of mailboxes per database in the Exchange organization.
[PS] C:\>Get-Mailbox | Group-Object -Property:Database | Select-Object name,count Name Count ---- ----- MB-BR-01 23 MB-HO-01 192 MB-HO-02 178
As you can see the Group-Object command allows us to see a count of mailboxes based on different attributes or properties of the mailbox. For example a count of mailboxes that are and are not exempt from email address policies.
[PS] C:\>Get-Mailbox | Group-Object -Property:EmailAddressPolicyEnabled | Select-Object name,count Name Count ---- ----- True 392 False 1
And as a final example, a count of mailboxes by Office (notice that the 6 mailboxes with a null value are still included in the results).
[PS] C:\>Get-Mailbox | Group-Object -Property:Office | Select-Object name,count Name Count ---- ----- Branch Office 23 6 Head Office 364
Hi Paul,
I am trying to determine which mailboxes are active in my environment. By active, I mean mailboxes that have sent an e-mail in the last 90 days or perhaps accounts that are active in AD vs disabled.
Hey Paul – fun fact about your “get mailboxes per database” – it won’t return databases with no mailboxes.
Chris
HI Paul,
I can see someone already asked about historical data, but their question was not clear enough. Can you think of a way to obtain the number of Exchange boxes for each day of the last few years. I would like to draw a histogram of how that number grew in our Uni.
Thank you!
Exchange doesn’t keep that historical data for you. You’d need to have collected it yourself over that period of time, either with custom scripts or a reporting tool.
I think I have found a solution sort by lastlogontime export to Excel, Thanks
Hi Paul, How to obtain a list of active mailboxes, us in the DA changed the status of the account to disabled and in exchange we changed the status to not visible
What do you consider to be an active mailbox?
This is great, thank you!
I just have a small problem:
“Get-Mailbox | Group-Object -Property:ServerName | Select-Object name,count” doesn’t include empty databases into the count.
Can I somehow do that?
Hi, can I get the number of mailboxes in another month?, for example junuary of 2016
Thanks
I don’t understand your question.
This is wonderfully useful, and the article came up as the first hit when I googled how to do this exact thing.
Thanks 😀
Name Server CurrentMailboxesCount Max
Avtest KFDCEX25 0
DB_VIP01 KFDCEX25 14
DB_VIP02 KFDCEX25 20
and export to CSV file
Thank you for your effort, but what if i want to get the server name i can’t figure it out ..like this format:
Name Server CurrentMailboxesCount Max
—- —— ——————— —
Avtest KFDCEX25 0
DB_VIP01 KFrtttss5 14
DB_VIP02 KFttttrr5 20
Please help ..thank u in advance.
Server name attribute on mailboxes is not relevant any more, because mailboxes are homed to databases, not servers.
To determine the server name you’ll need to do an additional query to match a database to a server. But keep in mind also that databases can be replicated between DAG members, so there may not be just a single server name associated with that database.
Paul.. Never mind I figured it out..Used the Group-Object
Hi Paul, i cam across this post and was taking some knowledge out of it. I built the below code where I want to gather different values of Custom Attribute 2 and Count them and report them. i made this below taking reference from my previous code that i built on Activation preference found here, “https://gallery.technet.microsoft.com/Exchange-2013-Activation-7e95afff “.
Although i can get the output but the CA name has output like below
CA Name Count
xxx1,xxx1,xxx1,xxx1,xxx2,xxx2,xxx3 11
xxx1,xxx1,xxx2,xxx2
What i really want is
CA Name Count
XXX1 6
XXX2 4
how can i achieve this. Also i want if there are no values on that Attribute report them with the count as well. below is the code that I worked on. I am looking for answers everywhere but could not. Since I follow your posts rigroulsy i thought best bet is to ask your help…
#Script Information
########################### Add Exchange Shell##############################
If ((Get-PSSnapin | where {$_.Name -match “Microsoft.Exchange.Management.PowerShell”}) -eq $null)
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
}
######################### generate the HTML#################################
function _Drawme {
$Output =”
Exhange Audit Report
Generated $((Get-Date).ToString())
”
if($cacount.count -ne 0) {
$Output+=”
”
$Output+=”#CA NameCA Count”
$Output+=””
$AlternateRow=0;
foreach ($mbx in $cacount) {
$C++
$Output+=””
$Output+=”$C”
$Output+=”$($caname)
$($cacount)”
}
$Output+=””
}
Write-Output $Output
}
#########################Get The Users##################################
$objprop = @{ user = “”
caname = “”
cacount =””
}
$users = Get-Mailbox
ForEach ($user in $users)
{
$username = $user.Name
$caname = $users.CustomAttribute2
$cacount = $caname.Count
# Compare the server where the DB is currently active to the server where it should be
If ($cacount -ne 0)
{
$obj = New-Object -TypeName psobject -Property $objprop
$obj.user = $User.Name
$obj.caname = $caname.CustomAttribute2
$obj.cacount = $cacount.count
}
}
if ($cacount.count -ne 0)
{
Write-Host “CA Found….Sending Email” -ForegroundColor Red
$Output= _Drawme
#Send the Email
Send-MailMessage -From “noreplyaudit@xx.com” -To “Recipient 1 ” -Subject “Exchange Audit Report” -BodyAsHtml $Output -Priority High -SMTPserver “smtp.xx.com”
}
Else{
Write-Host “Nothing Found!!!!!!!!!” -ForegroundColor Green
}
Pingback: Few useful Commands for Exchange Server 2010 | Welcome to My World
Hello Paul:
I’m new to Power Shell so please bear with me.
I am trying to get a count of email addresses (hidden/unhidden) per GAL
Get-Mailbox | Group-Object -Property:GlobalAddressList -eq “blah blah GAL” | Select-Object Displayname, EmailAddresses, count
Tried this cmd and got:
Group-Object : A parameter cannot be found that matches parameter name ‘eq’.
At line:1 char:53
+ Get-Mailbox | Group-Object -Property:AddressList -eq <<<< "abbotsLEA GAL" |
Select-Object Displayname, EmailAddresses, count
Should I use the "contains" variable where I have -eq text?
Please can you advise.
Group-Object doesn’t work with comparison operators like -eq. If you’re ever in doubt about how a cmdlet works the best resource to start with is the TechNet page for that specific cmdlet.
In your case perhaps try something more like…
Get-Mailbox | Where {$_.GlobalAddressList -eq “GALName” -and $_.} | etc etc
Hi Paul,
How can I get active mailbox list from the exchange 2010 for the last month? Please help.
Depends what counts as an “active” mailbox for you.
Hello Paul,
Can you please share a command to find out the active mailboxes?
Hi Paul,
I wanted to see mailboxes and Distribution groups in Exchange Database. How can I check this?
Thanks
Anees
Hi,
How do can I list the number of user mailbox bot including resource mailboxes ect… just user mailbox count.
Thanks! 🙂
Neil
very helpful. I’m doing a migration from 2007 to 2013 for a client with 65 mailboxes. I kicked of the mailbox moves about 6 hours ago, and then went out for a few pints of beer with my mates. then i wanted to check on the progress, and remembered seeing this post. the summary tells me i’m about half-way through, so I can enjoy a few more, and tomorrow morning, resume the migration, swing client access, and be done with it. Thanks, Paul!
[PS] D:>Get-MoveRequest|Get-MoveRequestStatistics|Group-Object -Property StatusDetail|Select-Object name,count|ft -AutoSize
Name Count
—- —–
Queued 22
CopyingMessages 19
AutoSuspended 24
Hi Paul Cunningham,
Is there any PS command available to get number of messages sent by a mailbox??
Thanks
You can gather that type of information using message tracking log searches.
Hello Paul Cunningham
Thanks for your valuable response
I am using PS command
$var = get-messagetrackinglog -sender senders_email
$var.count
this gives number of message send by a user of mailbox, not the number of message sent by mailbox.
How can i get the total number of message sent by a mailbox not a user of mailbox
Thanks
First, be aware that the number of message tracking log entries does not equal the number of unique messages. Each unique message can generate multiple log entries. You’ll need to filter the results down to unique message IDs or pick one event ID to filter on.
Second, I’m not sure that I understand your scenario. Are you talking about a shared mailbox?
Obviously i know that each unique message can generate multiple log entries. I am using filter on Event Id
as follows
get-messagetrackinglog -sender senders_email | where-object {$_.EventID -eq “submit”}
Now come to the point, I have a mailbox named Azam whose primary smtp address is azam@corp.local, it also has a delegate with id neetu@corp.local. I am sending a message using primary smtp address i.e. azam@corp.loca, and also send a message using its delegate’s id i.e. neetu@corp.local. Now there are two messages sent by the mailbox named Azam.
Now, i wants to know the PS command which returns number of message send by mailbox Azam, and also size of all message sent by this mailbox.
Kindly reply with PS command
Thanks
In the log entry for source STOREDRIVER and Event ID RECEIVE there is some extra data that can data that can help differentiate between messages sent by the mailbox owner and messages sent on behalf of.
The Sender and ReturnPath fields are usually different in that situation.
Hi Paul,
when I run (Get-Mailbox -resultsize unlimited).count I get 5141 however when I ran the “Get-MailboxReport.ps1” the result was 2378. So not too sure why the discrepancy in numbers?
Which option are you using when you run the script?
And do you have more than one domain in your AD forest?
.get-MailboxReport.ps1 -server ServerName -filename users.csv
I just copied the script and placed it into a folder
I did nothing to the script. I ran it as is.
1 Domain and that’s it.
So with that syntax the script will report only mailboxes on “ServerName”.
If there are more servers in your org then that would explain the discrepancy.
To report on all mailboxes in the org you can run “.Get-MailboxReport.ps1 -all”
Sorry Paul wrong article! i will re-post here:
https://www.practical365.com/powershell-script-health-check-report-exchange-2010/
Joel
Thanks again Paul! simple and effective.
However, i keep getting this error when i run this and cant seem to figure it out…
[PS] C:scripts>.Test-ExchangeServerHealth.ps1 -Reportmode -Sendmail
Unexpected token ‘Mailbox’ in expression or statement.
At C:scriptsTest-ExchangeServerHealth.ps1:327 char:19
+ $mbrole = “Mailbox <<<< Server Role"
+ CategoryInfo : ParserError: (Mailbox:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
the error refers to the section in the script where variables for the server roles are initialized, here:
# The server roles must match the role names you see when you run Test-ServiceHealth.
$casrole = "Client Access Server Role"
$htrole = "Hub Transport Server Role"
$mbrole = "Mailbox Server Role"
$umrole = "Unified Messaging Server Role"
Thank you
Joel
Thanks Paul. What if I want to list mailboxes on ie. Exchange2013 ExchangeVersion : 0.20 (15.0.0.0) according to Get-mailbox, but Get-Mailbox -ExchangeVersion ’15’ whatever does not Work? We have Exch2010 and 2013
Br,. Tim
Hello Paul,
I really appreciate your effort here.
What if I want to count the number of mailboxes in mbx store MBXStore01 ? Can’t figure that out ..
‘
Br, Tim
(Get-Mailbox -Database MBXStore01).Count
Hello Paul: Please help. Our organization has a mixed mail envionment. We migrating from Exchange 2007 to Exchange 2010. We have 3 mailbox servers. We have 6 databases in a DAG. I’m looking for a PS script that can count the mailboxes across all 3 Exchange 2010, and exclude Exchange 2007.
Can you help?
Thank you.
You could write a script or even a one-liner to do it. Or you could just use my Get-MailboxReport.ps1 script to dump out a mailbox report and then filter in Excel to get the results you want.
https://www.practical365.com/powershell-script-create-mailbox-size-report-exchange-server-2010/
OK, thank you..
Just confirming my plan of actions
Hi, this counter is the number of mbxs created on that servers? How to find how many users are now using that server? Need to shutdown one of the MB server from DAG for a day, it’s need to move any mbxs from this server to avoid any connections issues?
If the server is a member of a DAG then you should only need to move active databases to another server. You could simply put the server in maintenance mode similar to when patching is being performed.
Eg:
https://www.practical365.com/how-to-install-updates-on-exchange-server-2010-database-availability-groups/
Paul,
Really appriciate if you could answer this question.
I need to know is it possible to get Mailbox Count using WMI query in Exchange 2010? if yes how?
Probably not. I’ve never seen anyone do it that way, thats for sure. Why not just use the PowerShell cmdlets that are built for this purpose? They’re quite easy to use.
Pingback: Exchange 2010 Database way too big for size of organization | Mountain Vista Technologies
Paul, hopefully this is not a silly question, but does this count also include detached mailboxes? if so, it there a filter to only include active mailboxes?
I don’t think so.
Simply Cool one… 🙂
Paul
I’m getting the following error… Please correct If I’m doing wrong
[PS] C:Windowssystem32>(Get-Mailbox) .count
Unexpected token ‘.count’ in expression or statement.
At line:1 char:21
+ (Get-Mailbox) .count <<<(Get-Mailbox -ResultSize unlimited) .count
Unexpected token ‘.count’ in expression or statement.
At line:1 char:43
+ (Get-Mailbox -ResultSize unlimited) .count <<<<
+ CategoryInfo : ParserError: (.count:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Mine:
(Get-Mailbox).count
Yours:
(Get-Mailbox) .count
Your problem is the space before the .count. There’s not supposed to be a space there 🙂
Hi Paul,
It’s nice.
Really simple but very useful.
there is an option to count mailboxes with Get-MailboxDatabase -Status syntax ?
Is that a question or a statement?
you can also set your adserversettings to view the enitre forest:
Set-ADServersettings -ViewEntireForest:$true
So how do you handle multiple domains? These commands appear to only return counts of the users in 1 domain.
Hi Ben, adding the -IgnoreDefaultScope switch to the Get-Mailbox cmdlet should do the trick.