SMTP Port 25

Anything and Everything Related to Messaging and Collaboration, Active Directory and Scripting. It’s My Life!!!

Powershell to get Complete Mailbox Statistics in the Exchange 2007 Orginisation

Posted by Krishna - MVP on May 14, 2009

 

Below is the powershell command to export the complete details of the Mailbox in the Exchange Organization. Details like Name, Mailbox size (MB), Mailcount, Mailbox limits, Account Active or disabled, CreatedDate, Lastlogon time, Last logofftime etc into the CSV file. This Data can even imported in to the SQL database and Query to analyst the growth of the mailbox. If you collect these details on Daily basis and uploaded into SQL then you can easily get the details of the mailbox in seconds for auditing or capacity management etc.

With SQL integration you can query details like Top 100 mailbox, Top 100 Fastest growing mailbox, List of all active maibox, List of disabled mailbox, List of mailbox out of default quota limits, maiboxes not used in past few days. Newly created mailbox in past one month etc

Get-Mailbox -ResultSize Unlimited |  select DisplayName, Alias, Database, PrimarySmtpAddress,@{name=’IssuewarningQuota’;expression={if ($_.IssueWarningQuota -match “UNLIMITED”) {“-1″} else {$_.IssueWarningQuota.value.tomb() }}},@{name=’ProhibitSendQuota’;expression={if ($_.ProhibitSendQuota -match “UNLIMITED”) {“-1″} else {$_.ProhibitSendQuota.value.tomb() }}},@{name=’ProhibitSendReceiveQuota’;expression={if ($_.ProhibitSendReceiveQuota -match “UNLIMITED”) {“-1″} else {$_.ProhibitSendReceiveQuota.value.tomb() }}},WhenCreated  |export-csv C:\stats.csv
“DisplayName,Alias,MailboxSizeMB,ItemCount,PrimarysmtpAddress,IssueWarningQuotaMB,ProhibitSendQuotaMB,ProhibitSendReceiveQuotaMB,DatabaseName,CreationDate,LastLogonTime,LastLogoffTime,isActive” | out-file C:\MailstatsResult.csv
$csv = Import-csv -path “C:\stats.csv”
foreach($line in $csv)
{
 $MailboxStats =  Get-MailboxStatistics $Line.Alias | Select TotalItemSize,Itemcount,LastLogoffTime,LastLogonTime
 $L = “{0:N0}” -f $mailboxstats.totalitemsize.value.toMB()
 $Size = “”
 $Len = $L.Split(‘,’)
 for ($i=0; $i -lt $Len.length; $i++)
  {
   $Size = $Size +$Len[$i]
  }
  $temp=$Line.PrimarysmtpAddress
  $adobjroot = [adsi]”
  $objdisabsearcher = New-Object System.DirectoryServices.DirectorySearcher($adobjroot)
  $objdisabsearcher.filter = “(&(objectCategory=Person)(objectClass=user)(mail= $Temp)(userAccountControl:1.2.840.113556.1.4.803:=2))”
  $resultdisabaccn = $objdisabsearcher.findone() | select path

if($resultdisabaccn.path)
 {
 $actStatus = “1″
 }
 Else
 {
 $actStatus = “0″
 }
 
 $out =$Line.Displayname  + “,” + $Line.Alias  + “,” +  $Size + “,” + $MailboxStats.ItemCount  + “,” + $Line.PrimarySmtpAddress   + “,” +  $Line.IssueWarningQuota + “,” +  $Line.ProhibitSendQuota  + “,” +  $Line.ProhibitSendReceiveQuota + “,” + $Line.Database + “,” +  $Line.WhenCreated + “,” + $MailboxStats.LastLogonTime + “,” + $MailboxStats.LastLogoffTime + “,” + $actStatus
 $Out | Out-File C:\MailstatsResult.csv -Append
}

You can get the copy of the script in the below text file

http://powershell.com/cs/cfs-filesystemfile.ashx/__key/CommunityServer.Components.UserFiles/00.00.00.30.62/MailboxStats.txt

About these ads

12 Responses to “Powershell to get Complete Mailbox Statistics in the Exchange 2007 Orginisation”

  1. Andreas Bergman said

    I might be stupid, but i can’t get the script to run om my machine. Do I need to run on the exchange server?

    • Krishna said

      Hi,

      You can Execuite both in Exchagne server and local machine Exchange powershel console

      You can get faster result if you execute on Exchange server.

      Regards,
      Krishna

  2. Greg B said

    Great script. Very useful. However, if one has multiple domains, you need to add -ignoredefaultscope right after the get-mailbox command. This will return all mailboxes from the forest, not just from the current scope.

  3. Mario said

    Hi,

    Excellent script, but how can we include AD attribute “title”, tried to modify the script to add it but cannot seem to display the attribute in the report generated.

    You advice is appreciated.

    Thank you.

  4. Hello just thought i would let you know something.. This can be twice now i?ve landed on your weblog inside the last 3 weeks trying to find totally unrelated issues. Great Data! Keep up the great get the job done.

  5. Wubbo Oxhol said

    Very nice indeed.
    Does anyone know how to alter this to include first name, last name and all emailaddresses of the mailboxes?

  6. Narayana said

    Excellent script. Thank you.

    Can you please help me understand, what does the Active status value specify? is that based on usage?

    thanks
    Narayana

  7. Amazing! It is hard to get Exchange to spill its guts. Thank you!!

    -Kenny Dillon-
    Administrator Monkey

  8. Corey Zamara said

    is it just me or does the CSV not come out correct, in that it’s not proper delimited and not seperated by a coloum in excel?

  9. Sundar said

    Hi

    We are using exchange 2010 SP1. I need to prepare every month full report. I found your script very helpful. I just want to know whether we can include OU information as well. Because I need add which user belong to which OU. So I am manually exporting recipients list from EMS and past into excel sheet then I am comparing both excel sheet and merging. This is hectic job. Is there a script to get a report including OU? If so please let me know.

    Regards,

    Sundar

  10. ReMark said

    Hi,

    How do you import the data into SQL?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 49 other followers

%d bloggers like this: