Powershell counts of ageing mail + quota limits challenges

by brainwashed at 2013-04-26 13:39:53

Management will periodically ask me how many mail items users have that are aging past 18 and 24 months in age. They now want to add the get the user quota status in the same report. I’m trying to add the Storage Limit Status to a script that I’ve been using for some time to get an ‘old mail’ report and I’m not sure if I’m doing it correctly.

I’ve modified my original script to try to add the “storagelimitstatus” to is, but it doesn’t report on the mailbox status, it’s skipping that field in the CSV when it exports.

Any ideas as to a better way to add the quota limits to my original script so that get’s reported on?

My original script to get a report from a date in the past and newer:

$Givens = @{n=“Given Name”;e={$user.FirstName}}
$Lasts = @{n=“Last Name”;e={$user.LastName}}
$Itemsize = @{n=“Size of Items Found”;e={([Microsoft.Exchange.Data.ByteQuantifiedSize]$search.ResultItemsSize).ToMb()}}
$MailboxSize = @{n=“Mailbox Size”;e={$statistics.totalitemsize.value.toMB()}}
$mailboxes = Get-mailbox -resultsize unlimited
$mailboxes | foreach {
$user = Get-User $
$statistics = get-mailboxstatistics $

$search = Search-Mailbox –identity $_ -searchquery ‘received:<4/1/2011 OR sent:<4/1/2011’ -estimateresultonly
$_ | select $Givens, $Lasts, primarySMTPAddress, $ItemSize, $MailboxSize
} | Export-CSV -NoTypeInformation "c:\scripts\oldmail\newoldmail1.csv"
The script I’m working on that doesn’t give a quota status - note the added $StorageLimitStatus:

$Givens = @{n=“Given Name”;e={$user.FirstName}}
$Lasts = @{n=“Last Name”;e={$user.LastName}}
$Itemsize = @{n=“Size of Items Found”;e={([Microsoft.Exchange.Data.ByteQuantifiedSize]$search.ResultItemsSize).ToMb()}}
$MailboxSize = @{n=“Mailbox Size”;e={$statistics.totalitemsize.value.toMB()}}
$StorageLimitStatus = @{n=“StorageLimitStatus”;e={$statistics.StorageLimitStatus()}}
$mailboxes = Get-mailbox -resultsize unlimited
$mailboxes | foreach {
$user = Get-User $
$statistics = get-mailboxstatistics $

$search = Search-Mailbox –identity $_ -searchquery ‘received:<4/1/2011 OR sent:<4/1/2011’ -estimateresultonly
$_ | select $Givens, $Lasts, primarySMTPAddress, $ItemSize, $MailboxSize, $StorageLimitStatus
} | Export-CSV -NoTypeInformation "c:\scripts\oldmail\oldmail1.csv"

Example of script results:
“Given Name”,“Last Name”,“PrimarySmtpAddress”,“Size of Items Found”,“Mailbox Size”,“StorageLimitStatus”
Firstname",“Lastname”,"firstname.lastname@domain.com”,“0”,“26804”,
Firstname",“Lastname”,"firstname.lastname@domain.com”,“0”,“0”,
Firstname",“Lastname”,"firstname.lastname@domain.com”,“0”,“8”,
etc.
by nate-n8 at 2013-04-29 07:48:08
not sure if its the only thing, but take out the "()"

e={$statistics.StorageLimitStatus}