Need script to pull some details on exchange mailboxes

I'm running exchange 2007 and I have a list of about 1000 mailboxes that I need to get the following details on. How can I take acsv or text file with teh mailbxes and pull this data for each?

•      Size of mailbox
•      Last logged on with own account
•      Last time mail received

Who is Participating?

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

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.

Here's a basic one for you -

get-mailbox | get-mailboxstatistics | select-object DisplayName,TotalItemSize,LastLogonTime | export-csv file.txt

Not sure if there's a way to get the last email received, so I included lastlogontime (Figured maybe you're trying to clean up old mailboxes.)  Let me keep digging.

Edit - missed that you want last logged on with own account.  That's not tracked.  You can add LastLoggedOnUserAccount to see who last logged in.  So -

get-mailbox | get-mailboxstatistics | select-object DisplayName,TotalItemSize,LastLogonTime,LastLoggedOnUserAccount | export-csv file.txt
rdefinoAuthor Commented:
thanks. How to use this script to use a list of accounts from a  text file or cvs file. I have about 1000 accounts to check.
I would just run it against all mailboxes, then you can edit the CSV output.  Running the command like I listed it will give you ALL mailboxes.

If you want a subset based on a CSV/txt file you already have, it can be done.  Don't have that off the top of my head though.  Let me see what I can put together.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Try this -

Import-CSV C:\Users.csv | ForEach {Get-Mailbox -Identity "$($_.Name) *"} | get-mailboxstatistics | select-object DisplayName,TotalItemSize,LastLogonTime,LastLoggedOnUserAccount | export-csv file.txt

The $_.Name corresponds to the users full name.  You can substitute any number of variables there, include alias (For their AD account), etc.  To see all of these, pick one user and do this format -

get-mailbox useralias | fl *

Substitute useralias above with the users actual alias (smithj, for example).  You'll see ALL information, and then you can pick and choose the fields to work with.
rdefinoAuthor Commented:
the only issue with getting all mailboxes is then I have to sort out the 1000 or so I need. We have upwards of 10000 mailboxes in our environment.
Ahhh, yes, that makes a LOT more sense.  If you have a way that you delineate them in AD, we could use that as well.  FYI.
rdefinoAuthor Commented:
I get this error when running the script against my csv file.  I edited out the name of the dc in the error.

Get-Mailbox : The operation could not be performed because object ' *' could not be found on domain controller
At line:1 char:40
+ Import-CSV e:\mailboxes.csv | ForEach {Get-Mailbox -Identity "$($_.Name) *"} | g ...
+                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-Mailbox], ManagementObjectNotFoundException
    + FullyQualifiedErrorId : 2329A700,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
Drop the * - so -

Import-CSV C:\Users.csv | ForEach {Get-Mailbox -Identity "$($_.Name)"} | get-mailboxstatistics | select-object DisplayName,TotalItemSize,LastLogonTime,LastLoggedOnUserAccount | export-csv file.txt

Just to make sure - you're running this under Exchange Powershell, right?
rdefinoAuthor Commented:
yes, exchange shell.

but it still failing:

Get-Mailbox : Cannot bind parameter 'Identity'. Cannot convert value "" to type
"Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "The parameter value of this type
Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter cannot be empty.
Parameter name: identity"
At line:1 char:62
+ Import-CSV e:\mailboxes.csv | ForEach {Get-Mailbox -Identity "$($_.Name)"} | get ...
+                                                              ~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Mailbox], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.RecipientTasks.GetMailbox

Get-Mailbox : Cannot bind parameter 'Identity'. Cannot convert value "" to type
Sorry - two things.  Add "alias" to the top of your CSV, if you're using aliases.  Otherwise, use name or whatever you're importing.

Second, drop the get-mailbox since we're not getting them all now.

Import-CSV C:\input.txt | foreach {get-mailboxstatistics $_.alias} | select-object DisplayName,TotalItemSize,LastLogonTime,LastLoggedOnUserAccount | export-csv file.txt

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
Will SzymkowskiSenior Solution ArchitectCommented:
Try this script below...
Run this command in the EMS

Make sure that you have your CSV constructed like below


$Mailboxes = import-csv "c:\filename.csv"
ForEach ($Mailbox in $Mailboxes) {
Get-MailboxStatistics -Identity $Mailbox.Alias | select DisplayName, LastLogonTime, @{N="TotalItemSize(MB)";E={$_TotalItemSize.Value.ToMB()}} | Export-Csv "c:\mailboxstats.csv" -Append

Open in new window

That should do it.

rdefinoAuthor Commented:
Let me give this a try, thanks
rdefinoAuthor Commented:
Was able to pull the info. thanks
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

From novice to tech pro — start learning today.