<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Powershell to get Complete Mailbox Statistics in the Exchange 2007 Orginisation

Published on
11,636 Points
4,636 Views
5 Endorsements
Last Modified:
Approved
Powershell has been around for a little while now, still, some people have yet to discover the power that it can deliver. Here we use a Powershell script command to export the complete details of the Mailbox in the Exchange Organization to a CSV file.

It's really hard to keep track of the all the mailbox in the Exchange organization. Some mailboxes grow very big and may be unidentified, some mailboxes are disabled and it stays in the server for long time with out deletion. Because of these and more scenarios, we may not able to find which is top 100 mailbox in the Organization.

This script helps to get all the details into the CSV file. We can schedule this script on daily basis.  Please find the copy of the script below. It pulls details  like Name, Mailbox size (MB), Mailcount, Mailbox limits, Account Active or disabled, CreatedDate, Lastlogon time, Last logofftime etc into the CSV file.

Please have a look at the script below, and feel free to ask any questions as comment below.

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
}

Open in new window


You can copy the above script to the text file and Save it it as MailboxStats.ps1 in C:\

You can then Execute the script from Exchange Management Shell. Open Exchange Management Shell on the Exchange Server and type C:\Mailboxstats.ps1 to start the execution.

Be aware, this script can take some time to complete depending on the number of mailbox's in the organization.

As an enhancement to the script we can always make the script to upload to a SQL database and we can query for the details and also start looking at some trending information.

Regards,
Krishna
5
Comment
0 Comments

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Join & Write a Comment

Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month