The below script works fine, but I am looking to query the manager of each account queried. Our AD does hold the manager data in the organization tab, I just don't know the name of the object. A little help would be appreciated. Also, I realize my code is sloppy near the end, some pointers on the if then nesting would be nice too, as I couldn't get the if (instr... & instr...) then to work.
Note. the -vm is so that I don't list voicemail email accounts.
Const EXCHANGE_SERVER_NAME = "ABCXCHSVR"
Const VM = "-VM"
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connec
tion")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Comman
d")
objCommand.ActiveConnectio
n = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE"
)
objCommand.CommandText = "SELECT sAMAccountName, msExchHomeServerName, homeMDB, " &_
"department FROM 'LDAP://" & objRootDSE.Get("defaultNam
ingContext
") &_
"' WHERE objectClass='user' AND objectCategory='person'"
Set objRootDSE = Nothing
objCommand.Properties("Pag
e Size") = 1000
objCommand.Properties("Tim
eout") = 600
objCommand.Properties("Sea
rchscope")
= ADS_SCOPE_SUBTREE
objCommand.Properties("Cac
he Results") = False
Set objRecordSet = objCommand.Execute
Set objFileSystem = CreateObject("Scripting.Fi
leSystemOb
ject")
Set objFile = objFileSystem.OpenTextFile
("Users.tx
t", 2, True, 0)
While Not objRecordSet.EOF
strServer = "" : strServer = objRecordSet.Fields("msExc
hHomeServe
rName")
If InStr(1, strServer, EXCHANGE_SERVER_NAME, VbTextCompare) > 0 Then
strUsername = "" : strStore = "" : strDepartment = ""
strUsername = objRecordSet.Fields("sAMAc
countName"
)
strStore = objRecordSet.Fields("homeM
DB")
strDepartment = objRecordSet.Fields("depar
tment")
If instr(strServer, 2) = 0 Then
If instr(strServer, 3) = 0 &
If instr(1, strUsername, VM, VbTextCompare) = 0 Then
objFile.WriteLine strUsername & VbTab & strDepartment
End If
End If
End If
End If
objRecordSet.MoveNext
WEnd
Set objFile = Nothing
Set objFileSystem = Nothing
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
Start Free Trial