Powershell to get Complete Mailbox Statistics in the Exchange 2007 Orginisation

 

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

15 thoughts on “Powershell to get Complete Mailbox Statistics in the Exchange 2007 Orginisation

    • 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

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

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

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

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

  5. Excellent script. Thank you.

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

    thanks
    Narayana

  6. 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?

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

  8. Great script, thanks very much. I did have to just add “UseDatabaseQuotaDefaults” to the selection criteria (second line) so I can tell who had unlimited mailboxes, and who was set to default quotas.

    Cheers,
    Eathernet

  9. Does anyone have a script that can provide me with Exchange 2010 mailbox stats for just a small subset of users, say for instance five & for 30, 60, 80 & 180 days? This is in a DAG Exch 2010 environment. Thank you.

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 )

Google+ photo

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

Connecting to %s