The migration process used to move a number of mailboxes created a couple hundred dead mailboxes objects in our environment. Their mailbox information needed to be cleared before their mailboxes could be migrated to the server for the final time. To fix this, I looked into a script. First I found the script at TelnetPort25, here. This script goes through the entire environment and purges all deleted and non-system mailboxes. This would work great, but querying an environment with literally thousands of mailboxes is a daunting task.
That's when I found this script that would simply dump all the deleted-not-purged mailboxes on a specific server. Running this script generates a CSV file with their displayname, and some additional information. I copied the displayname field out of Glen's script and pasted to a text file to use and re-wrote Telnet's to fit my purpose.
Note: uncomment the line ' objExchange_Mailbox.Purge when you feel the script is working correctly.
'===================================================='
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: PurgeSelectedMailboxes.VBS
'
' AUTHOR: Eric Woodford - EricWoodford@gmail.com
' DATE : 3/10/2008
'
' COMMENT: Purge listed mailboxes on this Exchange server.
' Must be ran from the server.
'
'====================================================
Const cWMINameSpace = "root/MicrosoftExchangeV2"
Const cWMIInstance = "Exchange_Mailbox"
strComputerName = "."
strPathToCSV = "c:\"
strListofNames = "names.txt"
Set objfso = CreateObject("scripting.filesystemobject")
Set infile = objfso.opentextfile(strPathtoCSV&"\"&strListofNames,1)
Set wmiConn = GetObject("WinMgmts:{impersonationLevel=impersonate}!\\" & strComputerName & "\root\microsoftexchangev2")
If Err.Number <> 0 Then
WScript.Echo "Cannot connect to the Exchange WMI Namespace"
Wscript.Quit
End If
haltloop = false
DO While (not inFile.atendofstream)
strUserDisplayName = inFile.readline
WScript.Echo strUserDisplayName
strWQL = "SELECT * FROM Exchange_Mailbox WHERE MailboxDisplayName = '" & strUserDisplayName & "'"
' filter collection to only selected names
WScript.Echo " Searching... Please wait"
Set wmiColl = wmiConn.ExecQuery(strWQL)
WScript.Echo "Found "&wmiColl.count & " matching mailboxes"
For Each objExchange_Mailbox In wmiColl
WScript.Echo "Processing: " & strUserDisplayName
' objExchange_Mailbox.Purge
next
Loop
infile.close
Set wmiColl = Nothing
Set objWMIExchange = Nothing
set objfso = Nothing
Wscript.Echo "Script Completed"
Comments
Post new comment