Link to home
Start Free TrialLog in
Avatar of rdefino
rdefinoFlag for United States of America

asked on

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
Avatar of dipersp
dipersp
Flag of United States of America image

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
Avatar of rdefino

ASKER

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.
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.
Avatar of rdefino

ASKER

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.
Avatar of rdefino

ASKER

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
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?
Avatar of rdefino

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of dipersp
dipersp
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rdefino

ASKER

Let me give this a try, thanks
Avatar of rdefino

ASKER

Was able to pull the info. thanks