We help IT Professionals succeed at work.

Need help with Exchange Get-Mailbox reporting?

355LT1
355LT1 used Ask the Experts™
on
How can I modify the PS1 file to report the last 30 days or last 60 days of Exchange 2007 mailboxes recently created ?

$mbxs = Get-Mailbox -ResultSize Unlimited | Where-Object {($_.WhenCreated).Year –eq 2011}
$all = @()

foreach ($mbx in $mbxs) {

   $mbxstat = Get-MailboxStatistics $mbx.alias

   $out = new-object psobject  
   
   $out | add-member noteproperty Name $mbx.Name
   $out | add-member noteproperty Servername $mbx.ServerName
   $out | add-member noteproperty Database $mbx.Database
   $out | add-member noteproperty MailboxSize $mbxstat.TotalItemSize

   $all += $out
}

 $all | export-csv J:\User2011.csv


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
Try this for the the last 30 days:

Get-Mailbox -ResultSize Unlimited | Where-Object {$_.WhenCreated -ge ((Get-Date).Adddays(-30))}

Author

Commented:
I am aware of that one line command , I need to use it in the same PS1 to create a decent csv file. Just not sure how.
Top Expert 2011
Commented:
save this in a ps1 file for mailboxes created in the last 30 days:

$mbxs = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.WhenCreated -ge ((Get-Date).Adddays(-30))}
$all = @()

foreach ($mbx in $mbxs) {

   $mbxstat = Get-MailboxStatistics $mbx.alias

   $out = new-object psobject  
   
   $out | add-member noteproperty Name $mbx.Name
   $out | add-member noteproperty Servername $mbx.ServerName
   $out | add-member noteproperty Database $mbx.Database
   $out | add-member noteproperty MailboxSize $mbxstat.TotalItemSize

   $all += $out
}

 $all | export-csv E:\temp\Userlast30days.csv