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
pastrangerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

suriyaehnopCommented:
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

0
Rajkumar-MCITPCommented:
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
0
SeaSenorCommented:
I have two I run, but you might need to add to this to get exactly what you want.

First one:

Get-Mailbox -server "emailserver" | Select Name,@{label="Warning";expression={$_.IssueWarningQuota -replace "MB"," MB"}},@{label="Prohibit";expression={$_.ProhibitSendQuota -replace "MB"," MB"}} | Export-csv c:\mailboxquotas.csv
#Send an email

$FromAddress = "youremail@company.com"
$ToAddress = "youremail@company.com"
$MessageSubject = "Mailbox Quota Report"
$MessageBody = "woot"
$SendingServer = "your email server name"
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("c:\Mailboxquotas.csv")
$SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

Second one:

Get-mailboxstatistics -server "emailserver" | sort-object -property totalitemsize -descending | select-object displayname, @{ expression={$_.TotalItemSize.Value.ToMB()} }, storagelimitstatus, itemcount,  lastloggedonuser, lastlogontime, lastlogofftime, servername, databasename | Export-csv c:\mailboxes.csv

#Send an email

$FromAddress = "youremail@company.com"
$ToAddress = "youremail@company.com"
$MessageSubject = "Mailbox Quota Report"
$MessageBody = "woot"
$SendingServer = "your email server name"
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody
$Attachment = New-Object Net.Mail.Attachment("c:\Mailboxes.csv")
$SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

Once you get the code you want, save them in a .ps1 file.
You can run them and it will send the reports to you in an email

Also, from any computer that has exchange management console installed, you can call this from a batch file:

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\v14\bin\exshell.psc1" -noexit -file \\servershare\folder\filename.ps1

I'm sure you know to replace the "\\servershare\folder\filename.ps1" with the path to your own .ps1 file.
And to add your correct email info into the scripts.  

those two in combination get you about everything you need in general. I could never get them to work together in one script.

They work great, and i really like getting the email reports.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

pastrangerAuthor Commented:
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.
0
SeaSenorCommented:
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.

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_24213395.html?sfQueryTermInfo=1+10+30+combin+csv
0
SeaSenorCommented:
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
0
pastrangerAuthor Commented:
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.
0
SeaSenorCommented:
It is actually in the script, but it does not return any results for me. Just an empty column.
0
SeaSenorCommented:
Here is a slightly updated version... I have 're-ordered' the columns to give it a little better readability.

haven't sorted out the 'sorting' of it though :)
MailboxInfo.txt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pastrangerAuthor Commented:
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. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.