Solved

Get-Mailboxstatistics Script in Exchange 2010

Posted on 2012-04-03
10
1,912 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
ID: 37799778
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
ID: 37799867
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
ID: 37806253
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
Does Powershell have you tied up in knots?

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

 

Author Comment

by:pastranger
ID: 37810336
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
ID: 37811674
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
 
LVL 8

Expert Comment

by:SeaSenor
ID: 37812635
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
ID: 37812666
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
ID: 37812724
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
ID: 37813076
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
ID: 37814871
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this video we show how to create a Distribution Group 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 >>…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

831 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