Export mailbox statistics for specific users from CSV

Hi everyone,

How can I make this work?


   
 $Users = Import-Csv C:\x.csv
  foreach ($User in $Users) {(Get-mailbox -Identity $User.PrimarySMTPAddress) | Get-MailboxStatistics | Select DisplayName, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime | Export-CSV c:\test.csv}
MargaritaSystems AdministratorAsked:
Who is Participating?
 
Todd NelsonSystems EngineerCommented:
Out-File will not give you a properly formatted CSV file.

@Margarita ... Based on your script and the existing CSV file, use the following information...

The input CSV file (x.csv) should look something like this at a minimum, with "Users" as the header of the CSV file...

Users
John
Jacob
Jeff
James

Open in new window



The script should look like this...

Import-Csv C:\x.csv | foreach { Get-Mailbox -Identity $_.Users | Get-MailboxStatistics | Select DisplayName, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime } | Export-CSV -notype C:\test.csv

Open in new window


...OR try this slightly shorter script...

Import-Csv C:\x.csv | foreach { Get-MailboxStatistics -Identity $_.Users | Select DisplayName, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime } | Export-CSV -NoType C:\test.csv

Open in new window



The output will look something similar to the following...

"DisplayName","ItemCount","TotalItemSize","LastLogonTime","LastLogoffTime"
"John","976","14.57 MB (15,278,403 bytes)","1/2/2018 10:50:46 AM","1/2/2018 11:21:11 AM"
"Jacob","440","17.43 MB (18,279,079 bytes)","1/4/2018 6:30:11 AM","1/4/2018 6:35:28 AM"
"Jeff","976","14.57 MB (15,278,403 bytes)","1/2/2018 10:50:46 AM","1/2/2018 11:21:11 AM"
"James","440","17.43 MB (18,279,079 bytes)","1/4/2018 6:30:11 AM","1/4/2018 6:35:28 AM"

Open in new window


Let us know.
0
 
FOXActive Directory/Exchange EngineerCommented:
1. Create the .csv file with the heading Users and list each by email address
2. Run the following command
Import-Csv 'c:\temp\users.csv' | %{(Get-Recipient $_.Users | Get-MailboxStatistics | Sort DisplayName | select DisplayName, ItemCount, TotalItemSize, LastLogonTime, LastLogoffTime)} | Out-file 'c:\temp\info.csv'


Open your .csv in notepad
0
 
MargaritaSystems AdministratorAuthor Commented:
Hi all I ended up doing this and it worked.

Thanks

$Users = Import-Csv C:\x.csv
  $collection = foreach ($User in $Users)  {(Get-mailbox -Identity $User.PrimarySMTPAddress | Get-MailboxStatistics | Select DisplayName, TotalItemSize)}
 $collection |  Export-CSV c:\test.csv
0
 
MargaritaSystems AdministratorAuthor Commented:
Thank you both
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.