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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.