brain dump far away from /dev/null


Get a list of all disconnected mailboxes in Exchange 2010

The following script cleans up all your Exchange databases (necessary to get a fresh list of all disconnected mailboxes) and creates an HTML and CSV file containing:

  • DisplayName of the mailbox
  • ServerName, on which the mailbox is stored
  • DatabaseName, in which the mailbox is stored
  • DisconnectDate, when the mailbox was disconnected from the user account (the HTML output is also sorted by this column)
  • DisconnectReason, guess it: why the mailbox was disconnected (i.e. because the user account was disabled)

Just copy&paste these lines into a powershell script:

# ExportDisconnectedMailboxes.ps1
# This script runs "Clean-MailboxDatabase" on all
# available databases and creates an HTML report
# of all disconnected mailboxes.
# Revision History
# 2012-01-20 Christoph Holas    Initial Version
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Get-MailboxDatabase | Clean-MailboxDatabase
$MailboxDatabases = Get-MailboxDatabase
$DiscMailboxes = $MailboxDatabases | ForEach-Object { Get-MailboxStatistics -Database $_.Name | Where-Object {$_.DisconnectDate -ne $null}} | select DisplayName,ServerName,DatabaseName,DisconnectDate,DisconnectReason | sort DisconnectDate
$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 3px;border-style: solid;border-color: black;}"
$a = $a + "</style>"
$DiscMailboxes | ConvertTo-Csv | Out-File DisconnectedMailboxes.csv
$DiscMailboxes | ConvertTo-Html -head $a | Out-File DisconnectedMailboxes.html

Don't hesitate to write a comment if this script was (not) helpful to you. 🙂


Exchange 2010: count messages in local mail queue

Hi there. Here's just a little script before I leave the office for today. If you want to know how many email messages are in your local mail queue (no matter which Exchange role: Mailbox, CAS, HubTransport or Edge) just run the following command in your Exchange PowerShell:

Get-Queue | where {$_.MessageCount -ne "0"} | select messagecount | Measure-Object -Sum MessageCount | Select-Object -ExpandProperty Count

I have optimized the output to be easily interpreted by our monitoring system.


How to enable a mailbox or distribution group to receive mail from external senders

In Exchange 2010 you can permit or deny that unauthenticated users (ie senders outside of the Exchange organisation) send mails to a mailbox or distribution group. This setting can be set either in the EMS (PowerShell) or in EMC (console).