Link to home
Start Free TrialLog in
Avatar of pastranger
pastrangerFlag for Taiwan, Province of China

asked on

Get-Mailboxstatistics Script in Exchange 2010

Hi I am currently working on a script to get the following information in a mailbox DB.
I will need to get a mailbox DB's users, Totalitemsize, Item Count, Storage Limit Status, Disconnect Date, Issue Warning Quota, ProhibitSend Quota, and ProhibitSendReceive Quota.

I can get all the information from the script below, but not the quota information.
I have also tried something like Get-Mailbox | Get-mailboxstatistics, but it didn't work for me. Do you have any suggestion?

Get-MailboxStatistics -database 'DB Name' | sort-object -property totalitemsize -descending | select-object DisplayName, TotalItemSize, ItemCount, storageLimitStatus, @{expression={$_.totalitemsize.value.ToMB()};label="Size(MB)"}, LastLogonTime, DisconnectDate | export-csv C:\MailDB\DBName.csv
Avatar of suriyaehnop
suriyaehnop
Flag of Malaysia image

Please test this:

Import-Csv C:\PS\GroupOFCompanies.csv | foreach { Get-Mailbox -Identity $_.displayname } | ft alias,issuewarningquota,prohibitsendquota,prohibitsendreceivequota, `
#@{label = 'Status';expression={$mbx=Get-MailboxStatistics -Identity $_;$mbx.storagelimitstatus }}, `
@{Label='Size(MB)';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.totalitemsize.value.toMB()}}, `
@{Label='DatabaseName';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.DatabaseName}}, `
@{Label='ItemsCount';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.ItemCount}}, `
@{Label='StorageLimitStatus';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.StorageLimitStatus}}, `
@{Label='DisconnectDate';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.DisconnectDate}}, `
@{Label='LastLogonTime';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.LastLogonTime}}

Open in new window


or

Get-Mailbox -ResultSize Unlimited | ft alias,issuewarningquota,prohibitsendquota,prohibitsendreceivequota, `
#@{label = 'Status';expression={$mbx=Get-MailboxStatistics -Identity $_;$mbx.storagelimitstatus }}, `
@{Label='Size(MB)';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.totalitemsize.value.toMB()}}, `
@{Label='DatabaseName';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.DatabaseName}}, `
@{Label='ItemsCount';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.ItemCount}}, `
@{Label='StorageLimitStatus';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.StorageLimitStatus}}, `
@{Label='DisconnectDate';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.DisconnectDate}}, `
@{Label='LastLogonTime';expression={$mbx=get-mailboxstatistics -identity $_;$mbx.LastLogonTime}}

Open in new window

Avatar of Rajkumar Duraisamy
you can try this out

Get-Mailbox -Database “Database Name” -ResultSize Unlimited | Get-MailboxStatistics | select-object DisplayName, TotalItemSize, ItemCount, storageLimitStatus, @{expression={$_.totalitemsize.value.ToMB()};label="Size(MB)"}, LastLogonTime, DisconnectDate |sort-object -property totalitemsize -descending | export-csv C:\MailDB\DBName.csv

for more info http://msexchange2010.info/ems/?p=1356
SOLUTION
Avatar of SeaSenor
SeaSenor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pastranger

ASKER

Thanks everyone. Below is the reply to all your answers.

Hi, suriyaehnop,
I have tried your scripts, but looks like it did not work.

Hi  Rajkumar,

This is the first time I can get that Get-Mailbox | Get-Mailboxstatistics work, but there's no information showed in Disconnect Date.

Hi SeaSenor,

Your scripts works pretty good, but I would like to combine both of the csv file into one without doing it in other tools, so that's why I need all of the information to be gain by one script.

Regards.
I have yet to get all of those things to work in one script... that's why I have two.

you can open both csv files in excel as usual, then just copy and paste the other info....OR....There is also scripting available to merge the data in excel to form one file.
here's a link to one of many of these type of questions.....You can probably use it.

https://www.experts-exchange.com/questions/24213395/How-can-i-use-vba-to-combine-csv-files.html?sfQueryTermInfo=1+10+30+combin+csv
Try this:

change the extension of the attached file from .txt to .ps1 then run it from exchange powershell.

it will create a .csv file on your C:\ drive

it contains all of what you ask, except the "disconnectdate"  which I'm not sure what that is.
It does have the lastlogofftime though if that's what you mean.
MailboxInfo.txt
Thanks SeaSenor. I will definitely try it and update later.

For the disconnectdate is a property of a mailbox that has not been purged from a database but has no AD object to connect to.
It is actually in the script, but it does not return any results for me. Just an empty column.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Seasenor,

I have tried that script, and to be honestly, I love it although it took some time for the script to generate the report for one DB.
However, that should be fine as it gets lots of information out for me.
For the disconnect date, that one still returns an empty value to me, and I guess the reason should be that the script only catches the mailboxes which are currently connecting to an AD object. Am I correct?

If you use the following script which I am using right now, you will see it will catch all the mailboxes and has values in disconnect date if you have ever deleted a mailbox in recent days and not purged.

Get-MailboxStatistics -database 'DB Name' | sort-object -property totalitemsize -descending | select-object DisplayName, TotalItemSize, ItemCount, storageLimitStatus, @{expression={$_.totalitemsize.value.ToMB()};label="Size(MB)"}, LastLogonTime, DisconnectDate | export-csv C:\DBName.csv

I will give you the point, but if you can help to check if the script can be modified to catch all the mailboxes, that will be even better. :)