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


thanks
rdefinoAsked:
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.

diperspCommented:
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
0
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.
0
diperspCommented:
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.
0
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.

diperspCommented:
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.
0
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.
0
diperspCommented:
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.
0
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
'xxxxxxxxx.com'.
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
0
diperspCommented:
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?
0
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
0
diperspCommented:
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
1

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

Alias
mikesmith
davewells
etc...

$Mailboxes = import-csv "c:\filename.csv"
ForEach ($Mailbox in $Mailboxes) {
$Mailbox.Alias
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.

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

From novice to tech pro — start learning today.