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
Feb 22 2008, 02:28 AM
by
Joel Stidley