• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 82
  • Last Modified:

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
0
rdefino
Asked:
rdefino
  • 6
  • 6
2 Solutions
 
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

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

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now