When Exchange disconnects a mailbox after running either the
Disable-Mailbox or Remove-Mailbox cmdlet, it stamps the current date
and time in the mailbox’s DisconnectDate property. This marks the start
of the clock that ticks down until the retention time expires. The
retention time for deleted mailboxes is a property of a mailbox
database and can differ from the default 30 days. For example, for
legal reasons, you might want to remove or retain mailboxes for some
classes of employees for different periods. This is easily achieved by
placing the employee mailboxes in databases that are configured with
different retention periods. You can use this command to see the
current deleted mailbox retention period for all the databases in the
organization:
Get-MailboxDatabase | Select Name, MailboxRetention
Setting
a different retention period is a matter of using Set-MailboxDatabase
to set the desired value. For example, to set a mailbox retention
period of 60 days for the VIP Data database, you would use this command:
Set-MailboxDatabase –Identity 'VIP Data' –MailboxRetention 60
EAC
includes the Connect Mailbox option (in the list revealed by the
ellipsis) to view disconnected mailboxes and then connect a selected
mailbox back to an Active Directory account (Figure 1).
This option works by scanning all the mailbox databases on a selected
server to detect disconnected mailboxes. The administrator can then
select a mailbox and click the Connect icon (above Display Name in the
figure) to force EAC to search for a suitable Active Directory account
to which it can connect the mailbox. If EAC can find a suitable match
in Active Directory, it reconnects the mailbox. If not, EAC displays a
dialog box to enable the administrator to select the correct Active
Directory account to which the mailbox should be reconnected. It is
possible that no suitable Active Directory accounts can be found, as
when all available accounts are already connected to a mailbox. If this
happens, you can create a new Active Directory account and then rerun
the option. EAC detects the new account and enables you to reconnect
the mailbox to it.
It’s
more fun to do the work through EMS because you learn more about
Exchange by exploring the different steps that are involved in the
process. First, you have to execute a command like this to retrieve
information from a database about the mailboxes that are in this state:
Get-MailboxStatistics –Database DB2 –Filter {DisconnectDate –ne $Null}
| Format-List DisplayName, DisconnectDate, DisconnectReason
If you want, you can execute much the same command to discover details about all disconnected mailboxes on a server:
Get-MailboxStatistics –Server ExServer2 –Filter {DisconnectDate –ne $Null}
| Format-List DisplayName, DisconnectDate, DisconnectReason, Database
You
see values such as SoftDeleted and Disabled reported as the reason a
mailbox was disconnected. Mailboxes shown as SoftDeleted are those that
have been moved to another database. They are retained in the original
database just in case the mailbox move is affected by a problem that
leaves the new mailbox in an inconsistent or corrupted state for some
reason. Keeping the original mailbox following a move enables an
administrator to reconnect the user to this copy if the need arises.
Mailboxes
that are reported as Disabled are those that have been disabled through
EAC or by running the Disable-Mailbox command in EMS. Sometimes it can
take a little while after a mailbox is disabled or removed before it
shows up on the list of disconnected mailboxes. This could occur
because Active Directory hasn’t replicated the disconnected status for
the mailbox to the domain controller EMS is using. It might also be
that the Store has not yet stamped a disconnected date on the mailbox,
so the filter EMS uses to find disconnected mailboxes doesn’t pick it
up.
After you have identified a disconnected mailbox that needs
to be reconnected, you can use the Connect-Mailbox cmdlet to do the
job. The easiest situation is when Exchange can match the disconnected
mailbox to an Active Directory user account by reference to the name of
the Active Directory account by using the values contained in the
DisplayName and LegacyExchangeDN properties of the disconnected
mailbox. For example, if you have an account called John Smith and a
disconnected mailbox whose display name is also John Smith, it’s likely
that the two are a match; it’s therefore acceptable to let Exchange
join the two:
Connect-Mailbox –Database VIP –Identity "John Smith"
Life
isn’t normally so straightforward. At least, not all the time.
Different naming schemes for Active Directory user accounts and
Exchange mailboxes can conspire to stop any attempt to match one with
the other. EMS flags an error if it can’t run Connect-Mailbox as
previously shown and find a matching Active Directory account. In this
case, you can always use the globally unique identifier (GUID) to
identify the mailbox in the database and direct Exchange to the precise
Active Directory account to which you want to connect the mailbox.
First, retrieve the GUID:
$Guid= (Get-MailboxStatistics –Database DB2 –Filter {DisconnectedDate –ne $null –and DisplayName
–eq 'John Smith'}.MailboxGuid
This returns a value such as ‘50e2778f-e8ae-40d7-9dd8-bb22a101e8e5’. You can now use that value to reconnect the mailbox:
Connect-Mailbox -Identity '50e2778f-e8ae-40d7-9dd8-bb22a101e8e5' -Database 'DB2'
-User 'contoso.com/Exchange Users/John Smith' -Alias 'JSmith'
The
mailbox GUID is the most precise method of identifying an Exchange
object in situations like this. It also is useful if you want to delete
a mailbox from a database before its retention period expires. This
code scans a database for a particular mailbox, saves its GUID in a
variable, and then removes the contents by using the Remove-Mailbox
cmdlet. Note the use of the StoreMailboxIdentity parameter in this
command.
$Mbx = Get-MailboxStatistics –Database 'DB1' | Where {$_.DisplayName –eq 'Redmond, Tony'}
Remove-Mailbox –Database 'DB1' –StoreMailboxIdentity $mbx.MailboxGuid
When you delete mailbox contents in this way, you will have to use a backup to retrieve them if necessary afterward.