Sometimes a user account is accidentally deleted. The corresponding exchange mailbox object is still there for a month.
After creating a new user object, this user object has to be connected to the old mailbox object.
In a large organization the number of exchange stores/databases is often high too. This gives you as sysadmin a lot of mouseclicks…. The next script helps you to get around this problem: it enumerates user and the store of the user’s mailbox and creates a logfile with datestamp. When you schedule this script let’s say weekly you can simple open the textfile of the week before the user account was deleted to find out in which store the old mailbox resides.
Follow the next steps to run the script (no admin rights needed):
- open your favorite text editor
- copy and paste the script into the editor
- save the script (for example c:tempstore.vbs)
- open a command prompt
- go to “c:temp”
- give “cscript store.vbs” (without quotes) and enter
The script:
' Name : store.vbs
' Description : script to log the mailbox store of all users
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 26-03-2010
' Level : intermediate
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRootDSE.Get("defaultNamingContext") & ">"
strFilter = "(&(objectCategory=person)(objectClass=user)(mail=*))"
strAttributes = "cn,mail,homemdb"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
LogPrint adoRecordset.Fields("cn").Value & ":" & adoRecordset.Fields("mail").Value &_
":" & adoRecordset.Fields("homemdb").Value
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
Function LogPrint(Message)
Const ForAppending = 8
strDate = Replace(Date,"/","-")
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = ObjFSO.OpenTextFile(strDate & "-UsersInStore.csv", ForAppending, True)
objTextFile.WriteLine Message
objTextFile.Close
Set objTextFile = Nothing
Set ObjFSO = Nothing
End Function
When you have problems/questions please post a reply.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV
[adrotate group="2"]
