Did you ever needed to supply a list of mailboxes containing the e-mail address, DisplayName, Database, TotalSize of mailbox and total Items of the mailbox.
There are various ways of obtaining this information but the easiest way would be with powershell.
The information you need is supplied by two commands:
There are various ways of obtaining this information but the easiest way would be with powershell.
The information you need is supplied by two commands:
- Get-mailbox
- Get-mailboxstatistics
So how do you get the information of those two commands in a single output?
Get-mailbox Name select-Object DisplayName,PrimarySmtpAddress,Database
Get-Mailboxstatistics Name Select-Object TotalItemSize,ItemCount
I used to create arrays and then merge them together but for this relatively simple task you need at least 15 lines of code.
So I looked for other ways doing this.
To get the size of a mailbox you use the command:
Get-MailboxStatistics MBXName select TotalItemSize,ItemCount
This will produce:
TotalItemSize is displayed in Bytes which is not easy to work with so you can use the following expression to get it in another format.
Get-MailboxStatistics MBXName select {$_.TotalItemSize.value.toMB()},ItemCount
This will produce:

This is still not easy to work with. We need a different header for the mailbox size.
Get-MailboxStatistics MBXName select @{n="Size(MB)" ;E = {$_.TotalItemSize.value.toMB()}},ItemCount
This will produce:
So we can use an expression to reformat the output. So can we use another command in the same way we reformatted the output? Yes you can.
Get-Mailbox MBXName Select-Object name,primarysmtpaddress,DisplayName,Database, @{e = {Get-MailboxStatistics $_.name select totalItemsize}}
This will produce:
The columnheader of "Get-MailboxStatistics ......" is actually:
Get-MailboxStatistics $_.name PipelineBreakpointerE4078E3092DF4dd9A469F3DC0CBB505C(00000000000000000110) select totalItemsize
This is stil not easy to work with.
If you combine the statement to convert-to-MB with the get-mailboxstatistics you can get something like this:
Get-Mailbox MBXName Select-Object name,primarysmtpaddress, DisplayName,Database,@{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{n="Items"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount}}
This will output:
If you want to create an overview of a complete database you would use the following command:
Get-Mailbox –Database SRV1\SG01\DB01 Select-Object name,primarysmtpaddress,DisplayName,Database,@{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{n="Items"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount}}
Remco
Get-mailbox Name select-Object DisplayName,PrimarySmtpAddress,Database
Get-Mailboxstatistics Name Select-Object TotalItemSize,ItemCount
I used to create arrays and then merge them together but for this relatively simple task you need at least 15 lines of code.
So I looked for other ways doing this.
To get the size of a mailbox you use the command:
Get-MailboxStatistics MBXName select TotalItemSize,ItemCount
This will produce:
TotalItemSize is displayed in Bytes which is not easy to work with so you can use the following expression to get it in another format.Get-MailboxStatistics MBXName select {$_.TotalItemSize.value.toMB()},ItemCount
This will produce:

This is still not easy to work with. We need a different header for the mailbox size.
Get-MailboxStatistics MBXName select @{n="Size(MB)" ;E = {$_.TotalItemSize.value.toMB()}},ItemCount
This will produce:
So we can use an expression to reformat the output. So can we use another command in the same way we reformatted the output? Yes you can.Get-Mailbox MBXName Select-Object name,primarysmtpaddress,DisplayName,Database, @{e = {Get-MailboxStatistics $_.name select totalItemsize}}
This will produce:
The columnheader of "Get-MailboxStatistics ......" is actually:Get-MailboxStatistics $_.name PipelineBreakpointerE4078E3092DF4dd9A469F3DC0CBB505C(00000000000000000110) select totalItemsize
This is stil not easy to work with.
If you combine the statement to convert-to-MB with the get-mailboxstatistics you can get something like this:
Get-Mailbox MBXName Select-Object name,primarysmtpaddress, DisplayName,Database,@{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{n="Items"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount}}
This will output:
If you want to create an overview of a complete database you would use the following command:Get-Mailbox –Database SRV1\SG01\DB01 Select-Object name,primarysmtpaddress,DisplayName,Database,@{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{n="Items"; e = {$MBXstat = Get-MailboxStatistics $_.name ; $MBXstat.itemcount}}
Remco

i'm in mix mode with exchange 2003 and exchange 2007..
ReplyDelete2 questions.
1) can i get all exchange mailboxes size, display and email addresses ?
2) can i just get all exchange 2007 mailboxes since it may not able to run to get on both version of exchange server?
Jimmywang100 at yahoo
@Jimmywang100:
ReplyDeleteIf you want to retrieve E2K3 mailbox sizes you have to use WMI. This can be done with powershell:
Get-WMIObject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName | sort-object MailboxDisplayName | ft MailboxDisplayName,Servername,StorageGroupName,StoreName,Size
You can use the get-mailbox command for mailboxes on E2K3 but alot of time these will display warning messages.
The best way for E2K3 is to use WMI.
To my mind only some tools are able to help with such problem. Fortunately I know one of them. It was found out at one soft blog and proved me for some minutes all its abilities for working out many kinds of problems in this sphere - recovery exchange server.
ReplyDeleteExcellent Post
ReplyDeleteThis helped me indirectly to build my own command
where I wanted to find the mailboxes with string " Support" and then their mailbox stats
Just in case if some one require that command
its here
_______________________________
Get-Mailbox -filter { DisplayName -like '*support*'} -ResultSize Unlimited -IgnoreDefaultScope |Get-MailboxStatistics | select Displayname,ItemCount,@{n="Size(MB)" ;E = {$_.TotalItemSize.value.toMB()}}
_______________________________
NOTE- Remove spaces before using the command.
Thanks again
Badhwar Nitin
Hi Guys try this. you can also get the department attribute with the details
ReplyDeleteGet-Mailbox |Select name,alias, @{n="Size(MB)";e = {$MBXstat = Get-MailboxStatistics $_.name; $MBXstat.totalItemsize.value.toMB()}},@{n="Department"; e = {$MBXstat = Get-user $_.name ; $MBXstat.Department}}