Link to home
Create AccountLog in
Avatar of terminalb
terminalbFlag for United States of America

asked on

Mailbox Report Script Help

Hello,

Exchange 2010 SP2
Server 2008 R2

I commonly run mailbox reports with the intent of exporting a .csv file containing common mailbox properties.  I have been using this:

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,LastLoggedOnUserAccount,LastLogonTime,@{expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,OrganizationalUnit | Export-Csv MailboxReport.csv -NoTypeInformation

The output shows each mailbox on a separate row with DisplayName being the first column.  The main prolbem is it's based on a Get-MailboxStatistics command which doesn't include the WindowsEmailAddress property.  I'm thinking a separate command that imports the MailboxStatistics .csv file and appends to it by adding the WindowsEmailAddress would do the trick, but I'm a little fuzzy on some of the finer details:

1. Other than adding a >>, is there any other method of appending to a .csv file?
2. If I do append to the .csv file already created with Get-MailboxStatistics, how can I ensure the WindowsEmailAddress for each mailbox is assigned the correct row for it's respective mailbox?
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

You can try adding the expression something like the below.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,LastLoggedOnUserAccount,LastLogonTime,@{expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,OrganizationalUnit,@{expression=(Get-Mailbox $_.displayname).windowsemailaddress;n="WindowsEmailAddress"} | Export-Csv MailboxReport.csv -NoTypeInformation
Avatar of terminalb

ASKER

I like the direction you took that, but I ran the script in a test server and received an error:

Select-Object : Key expression has no value.
At line:1 char:114
+ Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object <<<<  DisplayName,LastLoggedOnUserAccount,LastLogonTime,@{expression={$_.TotalItemSize.Value.ToKB()}},ItemCount,Organi
zationalUnit,@{expression=(Get-Mailbox $_.displayname).windowsemailaddress;n="WindowsEmailAddress"} | Export-Csv MailboxReport.csv -NoTypeInformation
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException
    + FullyQualifiedErrorId : DictionaryKeyMissingValue,Microsoft.PowerShell.Commands.SelectObjectCommand

Character 176 is just after the expression in your associative array.
ASKER CERTIFIED SOLUTION
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Perfect.  Apart from adding a space in-between Get-Mailbox and $_.displayname it was right on the money.  Thank you very much!