Delete mailbox (VBScript)

This code can be found in Chapter 5 of Exchange Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This script was originally published in the Exchange Cookbook,
' (http://www.exchangebookcook.com). Written by Paul Robichaux, 
' Missy Koslosky, and Devin Ganger. Redistributed with permission 
' of the publisher, O'Reilly & Associates.

' 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, <forestDN>" 
' ------ 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

This code has been viewed 3879 times.

New from the creators of TechTasks.com: StatSheet.com