Mailbox-Disabling a User (Mailbox Deletion)
Now that you have seen how to mailbox-enable a user, it seems a good time to show a code sample illustrating this concept:
' This code removes a user's mailbox.
Option Explicit
Dim strUserDN, objUser
' ------ SCRIPT CONFIGURATION ------
strUserDN = "<UserDN>" ' e.g. cn=DrAmy,cn=Users,dc=mycorp,dc=com
' ------ END CONFIGURATION ---------
Set objUser = GetObject("LDAP://" & strUserDN)
objUser.DeleteMailBox
objUser.SetInfo( )
WScript.Echo "Successfully deleted user's mailbox."Tip
Mailbox-disabling a user requires Exchange Data Administrator permissions.
Once again, this is a very simple script with one new method, the DeleteMailBox method. Unfortunately, you cannot use this method to mail-disable a user. So when you call this method, you should be sure that the user is mailbox-enabled versus mail-enabled. If you use this method on a mail-enabled user, you will get an error such as "This user does not have a mailbox." The quick way to ascertain whether a user has a mailbox or is simply mail-enabled is to check for the existence of the homeMDB attribute. If a user object has homeMDB populated, there is an associated mailbox for that account.
The DeleteMailBox method is actually not well named because it doesn't really delete the mailbox. In actuality, it disconnects the mailbox from the user. The mailbox, by default, will still exist in the exchange store for 30 days and can be reconnected to the same or any other user object that doesn't have ...