Top 20 Largest Mailboxes

Here is a script that will report your top 20 largest mailboxes. This could easily be changed to report the top 5 or top 50. You can also use my previous post to schedule this to run every morning or once a month.

There is additional code here to send to to your mailbox so you don’t have to go and track it down. You know the status just by looking at your email (which you do anyway).

$subject = "Exchange 2010 Mailbox Statistics"

$mailboxes = Get-Mailbox -ResultSize 'Unlimited' -RecipientTypeDetails Usermailbox | Get-MailboxStatistics | Sort TotalItemSize -desc | select-object DisplayName,ItemCount,TotalItemSize -First 20

$20LargestMailboxes = $mailboxes | ConvertTo-HTML -fragment

$Head = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' ''><html xmlns=''><head><style type='text/css'>TABLE{font-family: verdana,arial,sans-serif;font-size:11px;color:#333333;border-width: 1px;border-color: #a9c6c9;border-collapse: collapse;background-color:#a9c6c9;}TH{border-width: 1px;padding: 8px;border-style: solid;border-color: #a9c6c9;}TD{border-width: 1px;padding: 8px;border-style: solid;border-color: #a9c6c9;background-color:#d4e3e5;}</style></head>"

$Body = "<body><p><h2>Top 20 Largest Exchange 2010

$Tail = "<p>This script is run from PUTIL2DSM. D:\PSScripts\MailboxStats.ps1.</p>"

$Message = $Head + $Body + $Tail

Send-MailMessage -To -From -Subject $subject -SmtpServer -Body $Message -BodyAsHtml

Now, a bit of explaination of the code…

The variables $subject, $head, $body, $tail & $message all have to do with the sending of the email. the $head is where the table is built. If you don’t like the look of the table, try modifying this variable.

$Body is the table itself including the table header

$Tail is just a reminder as to where this script is ran from so the person that follows me will have a chance of finding it to modify it.

The $Message is the combination of all three. Make sure you update the Send-MailMessage line with your specific details. Otherwise, you will not get the email.

So, the Exchange specific line is really just the one or two at the top. Study it and let me know if you have questions.

Here is a sample of what the email will look like.

Exchange Top 20 Email

Top 20 Email Sample

Posted in Exchange, PowerShell, Scripting | Tagged , , | Leave a comment

Scheduling Exchange Powershell Scripts

Even an average  scripter knows that scripting can save days and weeks worth of manually doing a task over the coarse of a year. This post will start Exchange 2010 administrators toward scheduling those scripts that save so much time.

To use the Get-Mailbox command, you have to load the Exchange Shell into Powershell. While this is easy once you know the trick, it is not intuitive at all. I had to do a bunch of digging thru Internet searches to find out exactly how to do it. I hope you find this page quickly (which will give you even more time to do other tasks)

OK, we all know the Windows Scheduler, so I won’t bore you with the details. Create a new task. On the Actions tab create a new action. In the Settings box, type “Powershell.exe” in the Program/Script: textbox.

So far, so good. That is the intuitive part. Pretty straight forward don’t you think?  The next step is to add information to the Add arguments (optional): textbox.

-PSConsoleFile “<path to Exchange>\Exchange\V14\Bin\ExShell.psc1″ -Command <path to scripts>\<filename>.ps1

Note the three variables in this line. <path to Exchange>, <path to scripts> and <filename>. These will change based on your implementation so you will need to substitute your information here.

I also put <path to scripts> in the “Start in(optional): textbox. That way, if my script generates a log file, I don’t always have to put the full path in my script.

Finish creating the task with your triggers, etc. and your script should now run on a schedule.

Let me know how things work out.

“There is nothing so permanent as a temporary solution” – Me

Posted in Exchange, PowerShell, Scripting | Tagged , , | Leave a comment