Friday, 8 August 2008

Exchange 2003, WMI and Powershell - Part 4 (Disconnected Mailboxes)

In parts 1 , 2 , 3 we looked at retrieving mailbox information from Exchange 2003 using WMI and Powershell.

In part 4 we're going to take another look at this topic area for something slightly more advanced - how to get a list of all mailboxes which have been deleted, but are still in the time frame for 'Keep Deleted Mailboxes for: x days'.

A typical scenario might be a mailbox has been deleted incorrectly and you need to re-connect it to an AD account; however, since the AD account has gone, how do you know which Mailbox Store was the home for the mailbox?

In the Exchange management GUI you would need to browse through each mailbox store looking for mailboxes marked with the red cross. Not too bad a job if you only have one mailbox store, but if that number is in the 10's of Mailbox Stores then its a pretty tedious task.

Step forward Powershell!

Again use the Exchange_Mailbox class and this time look for the DateDiscoveredAbsentInDS value. This value gets populated after the mailbox has been marked for deletion. We look for a value which begins with "2", i.e. the mailbox has been deleted sometime after the year 2000 (there may be a better way to do this), and return info about each mailbox in this state, including the Servername and Mailbox Store Name so that you can easily track the mailbox down.

Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName | where { $_.DateDiscoveredAbsentInDS -like '2*' } | sort-object MailboxDisplayName | ft MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size,DateDiscoveredAbsentInDS


Update 12/08/08:

Thanks to Shay Levy who has come back with a better way to do this!

"Using a -filter parameter which makes your query run on the server and return only the relevant mailbox objects". You should find that this significantly improves the speed of the query. Check the comments for this post for full details.

Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "DateDiscoveredAbsentInDS is not null" | sort-object MailboxDisplayName | ft MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size

2 comments:

$hay@Israel said...

As far as I know, if DateDiscoveredAbsentInDS has a value then the mailbox is considered disconnected.

Filtering with where-object is performed AFTER you get all mailbox objects to your console, which can be quiet expensive to do. To boost performance you can use the -filter parameter which make your query run on the server and return only the relevant mailbox objects:

Get-Wmiobject -namespace root\MicrosoftExchangeV2 -class Exchange_Mailbox -computer ExchangeServerName -filter "DateDiscoveredAbsentInDS is not null" | sort MailboxDisplayName | ft MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size


Or even select only the properties you want using a query:

$query = "Select MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size From Exchange_Mailbox Where DateDiscoveredAbsentInDS is not null"
Get-Wmiobject -namespace root\MicrosoftExchangeV2 -computer ExchangeServerName -query $query | sort MailboxDisplayName | ft MailboxDisplayName,ServerName,StorageGroupName,StoreName,Size


---
Shay Levy
http://blogs.microsoft.co.il/blogs/ScriptFanatic

Jonathan Medd said...

Brilliant! Thanks so much for checking out the post and providing the improved ways to do this.