The SysAdmin Network

No more hiding in the server room

Exchange 2007 Powershell commands - Disconnected Mailboxes

Background information.
In Microsoft Exchange Server 2007, each mailbox consists of an Active Directory user and the mailbox data that is stored in the Exchange mailbox database.
All configuration data for a mailbox is stored in the Exchange attributes of the Active Directory user object.
The mailbox database contains the mail data that is in the mailbox associated with the user account.

When you create a mailbox for a new or existing user, the Exchange attributes that are required for a mailbox are added to the user object in Active Directory. The associated mailbox object in the Exchange mailbox database is not created until the mailbox either receives a message or the user logs on to it. If you create a new mailbox, and then remove or disable that mailbox before the mailbox object in the Exchange mailbox database is created, it will not be available as a disconnected mailbox.

In Exchange 2007 we have two options, Remove or Disable

Disable Mailbox command
Disable-Mailbox ALIAS

Remove Mailbox command
Remove-Mailbox ALIAS

If you remove a mailbox, the mailbox data that is stored in the Exchange mailbox database is marked for deletion and the associated user account is also deleted from Active Directory. To retain the user account and only disassociate the mailbox data from the user account, you must disable the mailbox.

Mailboxes that are disabled are retained for a specified amount of time based on the deleted mailbox retention settings configured for that mailbox database. By default Exchange retains a disconnected mailbox for 30 days. During this time, the disconnected mailbox can be recovered by associating it with an existing Active Directory user account.
To list all disconnected mailboxes run the following command

List all Disconnected Mailboxes
Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid

There are two operations you can perform on a disconnected mailbox:
1)Connect it to an existing user account in Active Directory. (as long as it doesn’t already have one associated with it)

Connect Disconnected Mailbox
Connect-Mailbox -Database "Mailbox Database" -Identity "USER NAME"


2)Permanently delete it from the Exchange mailbox database.

Permanently Remove Mailbox
Remove-Mailbox -Identity DOMAIN\ALIAS -Permanent $true



Remove single mailbox
Remove-Mailbox -Database -StoreMailboxIdentity -confirm:$false

Remove all at the same time
$users = Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid

Remove from all databases:

$users = Get-MailboxStatistics | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid,Database

$users | ForEach { Remove-Mailbox -Database $_.Database -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }

Views: 3209

Comment

You need to be a member of The SysAdmin Network to add comments!

Join The SysAdmin Network

© 2012   Created by Elizabeth Ayer and Michael Francis.   Powered by

Badges  |  Report an Issue  |  Terms of Service