Recipe5.3.Removing a Mailbox for an Existing User


Recipe 5.3. Removing a Mailbox for an Existing User

Problem

You want to remove the mailbox from an account while leaving the account intact.

Solution

Using a graphical user interface

  1. Log on to any machine in your domain that has the Exchange management tools installed.

  2. Open the ADUC snap-in (Users and Computers.msc).

  3. Locate the account whose mailbox you want to delete.

  4. Right-click the target account and choose the Exchange Tasks command.

  5. The Exchange Task Wizard will appear. (You may see a welcome page first; if so, click Next to dismiss it.)

  6. From the Available Tasks window, choose Delete Mailbox and click Next.

  7. The Delete Mailbox page appears, along with a warning that deleting the mailbox will delete the messages it contains. Click Next if you really want it deleted.

  8. The Task in Progress window will briefly appear, then you'll see a completion page that indicates whether the mailbox creation succeeded or not. Click Finish.

Using a command-line interface

Use 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

Discussion

In 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 Also

Recipes 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.



Exchange Server Cookbook
Exchange Server Cookbook: For Exchange Server 2003 and Exchange 2000 Server
ISBN: 0596007175
EAN: 2147483647
Year: 2006
Pages: 235

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net