Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2152
  • Last Modified:

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
0
pastranger
Asked:
pastranger
2 Solutions
 
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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
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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now