Exchange Exchange
A community dedicated to Exchange and related technology.
Quick PowerShell Tip using Get-MailboxStatistics
Joel Stidley's Blog



News

  • Be sure to enter our contest by sending an e-mail with an idea for our next podcast to: podcast@exchangeexchange.com

I saw this question over on the Ask a Question Page at the Exchange Ninjas site and decided that I should spend time away from my backlog of other work and answer the question instead.

 

Q: We need to get the users list from PowerShell sorting by database , mailboxsize & lastlogontime ( those who have not been logged on their mails for 60 days). I hope there should be merged these two cmdlets "get-mailbox "and "get-mailboxstatistics". The output should be as follows:  Alias,DisplayName,Mailboxsize,Lastlogontime,Database

 

The quick and dirty script looks like this:

Get-MailboxStatistics | where-object {$_.LastLogonTime -lt '12/23/2007'} | sort-object DatabaseName, TotalItemSize,LastLogonTime |  format-table  DisplayName, @{expression={$_.TotalItemSize.Value.ToMB()};label="TotalItemSize(MB)"}, LastLogonTime, DatabaseName

The output looks something like this:

DisplayName           TotalItemSize(MB) LastLogonTime       DatabaseName
-----------                 -----------------         -------------              ------------
JRWeb                                      0          10/10/2007 8:47:...          MB01
Summer Daey                            2          6/1/2007 2:05:18 AM       MB01
ConfRm-                                  97           12/22/2007 1:10:3...         MB01
John Mallard                         214           12/22/2007 1:59:2...          MB01
Joe King                                253          11/13/2007 2:14:...           MB01
SystemMailbox{CB...                0                                                   MB03
Peter Pope                           158           12/21/2007 1:11:0...          MB03
Denise Reynolds                    201          12/7/2007 8:25:57 AM        MB03
Purple Hayes                       240             12/22/2007 12:24:...          MB03
Joel Stidley                          252            12/22/2007 1:59:3...          MB03
Brenda Keene                        13           11/7/2007 3:15:5...           MB04
ConfRM-Polaroid                      9          12/20/2007 10:40:...            MB05
Rick Springfield                     178          12/22/2007 2:42:1...           MB05
Cherri Oldham                       270        12/17/2007 10:11...             MB05
Ryan Buyall                            477        12/22/2007 12:22:...             MB05
Will Lawrence                      786          12/21/2007 10:20:...             MB05

This script takes all of the mailbox statistics and then uses a where-object to filter out only mailboxes that haven't been logged into since the specified date. In theory you could grab this at run time with a little math or via a prompt. Then it sorts the data by Database, Mailbox size and then last login time.

Lastly, the format table display this data and formats the mailbox size in megabytes.


Posted Fri, Feb 22 2008 2:28 AM by Joel Stidley
Filed under:

Comments

Dougs Blog >> Exchange Server in the field wrote They say it better than I can...
on Mon, Jun 2 2008 3:23 AM

Just want to point you to a few blog articles I have read recently just in case your search doesn't reveal

ckemppel wrote re: Quick PowerShell Tip using Get-MailboxStatistics
on Wed, Jul 23 2008 12:39 PM

Hi Joel, the question asked is the same question I have;  While your script addresses part of the question it does not achieve the required result of merging the  "get-mailbox "and "get-mailboxstatistics" output into a single table so that the Alias and any other parameters desired from the get-mailbox command are available, have you had any further progress on this?

Joel Stidley wrote re: Quick PowerShell Tip using Get-MailboxStatistics
on Wed, Jul 23 2008 2:02 PM

ckemppel,

Which specific attributes are you looking to add?

chris.trotter@gmail.com wrote re: Quick PowerShell Tip using Get-MailboxStatistics
on Wed, Jul 29 2009 12:47 PM

I am interested in using a script like this, sorting by OU and then by TotalItemSize, but I cannot manage to make it work.  Suggestions?

Joel Stidley wrote re: Quick PowerShell Tip using Get-MailboxStatistics
on Wed, Aug 5 2009 4:27 PM

Chris, you might be able to use the Quest AD PowerShell or perhaps the Windows 2008 R2 cmdlets. Off the top you might be able to run: get-QADUser -SearchRoot 'company.com/UsersOU' | Get-MailboxStatistics | where-object {$_.LastLogonTime -lt '12/23/2007'} | sort-object DatabaseName, TotalItemSize,LastLogonTime |  format-table  DisplayName, @{expression={$_.TotalItemSize.Value.ToMB()};label="TotalItemSize(MB)"}, LastLogonTime, DatabaseName

you would do this for each OU, there are other things you could do to customize that.

© 2003-2009 NamedPipes Consulting. All other company and product names are property of their owners.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems