Solved

Get-Mailboxstatistics Script in Exchange 2010

Posted on 2012-04-03
10
1,879 Views
Last Modified: 2012-04-05
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
0
Comment
Question by:pastranger
10 Comments
 
LVL 18

Expert Comment

by:suriyaehnop
Comment Utility
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
 
LVL 15

Expert Comment

by:Rajkumar-MCITP
Comment Utility
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
 
LVL 8

Assisted Solution

by:SeaSenor
SeaSenor earned 300 total points
Comment Utility
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
 

Author Comment

by:pastranger
Comment Utility
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
 
LVL 8

Expert Comment

by:SeaSenor
Comment Utility
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
Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

 
LVL 8

Expert Comment

by:SeaSenor
Comment Utility
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
 

Author Comment

by:pastranger
Comment Utility
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
 
LVL 8

Expert Comment

by:SeaSenor
Comment Utility
It is actually in the script, but it does not return any results for me. Just an empty column.
0
 
LVL 8

Accepted Solution

by:
SeaSenor earned 300 total points
Comment Utility
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
 

Author Comment

by:pastranger
Comment Utility
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

Featured Post

Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Check out this infographic on what you need to make a good email signature that will work perfectly for your organization.
In this video we show how to create a User Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Mailb…
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now