# 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 ------
use Win32::OLE;
$strDCName = '<ServerName>';
# e.g. CONT-EXBE01
$strUserName = '/cn=<User>, CN=Users, <forestDN>';
# ------ END CONFIGURATION ---------
# find the target user
$strQuery = 'LDAP://' . $strDCName . $strUserName;
$theUser = Win32::OLE->GetObject($strQuery);
if (($theUser->HomeMDB eq '')) {
print $strUser . ' doesn\'t have a mailbox', "\n";
}
else {
$theUser->DeleteMailbox();
$theUser->SetInfo();
print 'Deleted mailbox for ' . $strUser, "\n";
}
|