Recipe 5.3. Removing a Mailbox for an Existing UserProblemYou want to remove the mailbox from an account while leaving the account intact. SolutionUsing a graphical user interface
Using a command-line interfaceUse exchmbx with the -clear switch to remove the mailbox from the specified user: > exchmbx -b <userDN> -clear Using VBScript' This code removes the mailbox associated with the specified ' account. Once it's gone, it can still be retrieved, until the ' deleted mailbox retention period expires ' ------ SCRIPT CONFIGURATION ------ strDCName = "<ServerName>" ' e.g., CONT-EXBE01 strUserName = "/cn=<User>, CN=Users, <ForestRootDN>" ' ------ END CONFIGURATION --------- ' find the target user strQuery = "LDAP://" & strDCName & strUserName Set theUser = GetObject(strQuery) if (theUser.HomeMDB = "") then WScript.Echo strUser & " doesn't have a mailbox" else theUser.DeleteMailbox theUser.SetInfo WScript.Echo "Deleted mailbox for " & strUser end if DiscussionIn keeping with science-fiction author Spider Robinson's famous dictum that it's easier to build a tape eraser than a tape recorder, it turns out that removing a mailbox is simpler than creating one. The CDOEXM DeleteMailbox method does all the dirty work. In the previous script, you have to supply the user's DN and the name of a DC, so that ADSI can be used to identify the mailbox; after that, deleting the mailbox itself is simple. When you delete the mailbox, two things happen: the mail-enabled attributes are removed from the user object (which will then be replicated to other DCs in the same domain, and then to GCs throughout the forest), and the mailbox table, and its associated data, will be marked for deletion in the information store. Don't delete a mailbox unless you really want to get rid of it, because once the store deletes it, you'll find it difficult to get it back; you can disconnect mailboxes or disable accounts if you want to prevent access while still preserving your opportunity to restore access later. See AlsoRecipes Recipe 5.1 and Recipe 5.2 for creating mailboxes and user objects, MS KB 297398 (HOWTO: Delete a Mailbox Using CDOEXM and Visual C++ ), and MSDN: IMailboxStore::DeleteMailbox. |