Recipe 17.14. Reconnecting a Deleted MailboxProblemYou want to reconnect a mailbox in the Exchange Store to a user object. SolutionUsing a graphical user interface
Using VBScript' This code reconnects a mailbox to a user. ' ------ SCRIPT CONFIGURATION ------ strComputer = "<Exchange Server>" ' e.g., ExchServer2 strUser = "<Userid>" ' e.g., jsmith strMailbox = "<Mailbox Alias>" ' e.g., jsmith ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & _ "\root\MicrosoftExchangeV2") set objDiscMbx = objWMI.ExecQuery("Select * from Exchange_Mailbox WHERE " _ & "MailboxDisplayName='" & strMailbox & "'",,48) for each objMbx in objDiscMbx objMbx.Reconnect strUser next Wscript.Echo "Successfully reconnected mailbox." DiscussionWhen you tell the system to delete an Exchange mailbox, it isn't really deleted. It is simply disassociated or disconnected from the user object. These mailboxes are referred to as orphaned or disconnected. Deleted mailboxes stay in this disconnected state for a configurable period, by default 30 days, and can be recovered any time in that period. To truly remove a mailbox before that time, you must purge the mailbox after the deletion. This recipe shows how to reconnect that disconnected mailbox back to the original user object, or, if you prefer, an alternate user object.
Using a graphical user interfaceYou may run into a case where the ESM doesn't show you a mailbox is disconnected when, in fact, you know it is. This can happen if you delete the mailbox and immediately look at it in ESM. In order to clear that condition, you will need to right-click on the mailboxes container and select Run Cleanup Agent, causing some house cleaning to be done. The mailbox should then show up as disconnected.
Using VBScriptThe Reconnect method is part of the Exchange_Mailbox class, which is new for Exchange 2003. In Exchange 2000, there was no method available to reconnect a mailbox via a script. Unfortunately, there are some serious flaws with this implementation of the Reconnect method, which severely limits its usability in some environments. The first flaw is that the WMI method must run directly on the Exchange Server with the disconnected mailbox, so the script must run on the Exchange server. You can't, for instance, have a script that runs from a workstation that will reconnect mailboxes on any of your Exchange servers. The second flaw is that you cannot specify the domain of the user you want to reconnect to the mailbox. In a single domain Exchange environment, this will be fine. Trying to reconnect a mailbox in a forest with the same user name in multiple domains could give unexpected results. See AlsoRecipe 17.15, Exchange Server 2003 SDK, MS KB 274343 (How to Recover a Deleted Mailbox in Exchange), MS KB 316792 (Minimum permissions necessary to perform Exchange-related tasks), and Exchange Server 2003 SDK: WMI Reference |