G
Guest
Below is code that I have to loop through my Active Directory and pull out fields. I would like to pull what I believe is the NT telephone number (General Tab on AD). I know this is an ADSI pull, but am I on the right track? I have pieced this code from snippets around the net
Also, is there a good documentation reference, that I can purchase? I already use ADSI CDO from WROX. I think it has a lot of things missing.
Thanks, John
Set objDomain = GetObject("WinNT://xxxxxxx.ins"
objDomain.Filter = Array("User"
For Each objUser In objDomai
Wscript.Echo(lcase(objUser.Name) & " " & strInfo
CheckForUser(lcase(objUser.Name)
Nex
Sub CheckForUser(strUserName
dim Con
set Conn = CreateObject("ADODB.Connection"
Dim objConnection, objCommand, objRecordSe
Dim objRootDSE, objIte
Dim strAMAccountNam
Dim strInfo, strSplit, strAllowIn, strReport
Set objConnection = CreateObject("ADODB.Connection"
objConnection.Open "Provider=ADsDSOObject;
Set objCommand = CreateObject("ADODB.Command"
objCommand.ActiveConnection = objConnectio
objCommand.CommandText = "<LDAP://dc=xxxxxxx,dc=ins>;(&(objectCategory=User) (email=*)(samAccountName=" &strUserName& "));sAMAccountName,distinguishedName;subtree
Set objRecordSet = objCommand.Execut
Set objRootDSE = GetObject("LDAP://rootDSE")
strDN = objRecordSet.Fields("distinguishedName"
intFirstPos = InStr(1, strDN, "/")
intSecondPos = InStr(1, strDN, "!"
intThirdPos = InStr(1, strDN, "IUSER"
if intFirstPos = 0 and intSecondPos = 0 and intThirdPos = 0 the
' wscript.Echo("DN:" & objRecordSet.Fields("distinguishedName"))
Set objItem = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName")
If objRecordset.RecordCount <> 0 The
strsAMAccountName = objItem.Get("sAMAccountName"
strName = objItem.displayNam
strInfo = "
strInfo = objItem.Inf
strTelephone = objItem.Telephon
strReports = "
if len(strInfo) > 0 the
strSplit = split(strInfo,"/"
strAllowIn = trim(strSplit(0)
if Ubound(strSplit)>0 the
strReports = trim(strSplit(1))
strReports = Replace(strReports, "'", "''"
end i
end if
wscript.Echo("Adding " &lcase(strsAMAccountName) & " " & strName & " " & objItem.email
End I
End I
End Sub
Also, is there a good documentation reference, that I can purchase? I already use ADSI CDO from WROX. I think it has a lot of things missing.
Thanks, John
Set objDomain = GetObject("WinNT://xxxxxxx.ins"
objDomain.Filter = Array("User"
For Each objUser In objDomai
Wscript.Echo(lcase(objUser.Name) & " " & strInfo
CheckForUser(lcase(objUser.Name)
Nex
Sub CheckForUser(strUserName
dim Con
set Conn = CreateObject("ADODB.Connection"
Dim objConnection, objCommand, objRecordSe
Dim objRootDSE, objIte
Dim strAMAccountNam
Dim strInfo, strSplit, strAllowIn, strReport
Set objConnection = CreateObject("ADODB.Connection"
objConnection.Open "Provider=ADsDSOObject;
Set objCommand = CreateObject("ADODB.Command"
objCommand.ActiveConnection = objConnectio
objCommand.CommandText = "<LDAP://dc=xxxxxxx,dc=ins>;(&(objectCategory=User) (email=*)(samAccountName=" &strUserName& "));sAMAccountName,distinguishedName;subtree
Set objRecordSet = objCommand.Execut
Set objRootDSE = GetObject("LDAP://rootDSE")
strDN = objRecordSet.Fields("distinguishedName"
intFirstPos = InStr(1, strDN, "/")
intSecondPos = InStr(1, strDN, "!"
intThirdPos = InStr(1, strDN, "IUSER"
if intFirstPos = 0 and intSecondPos = 0 and intThirdPos = 0 the
' wscript.Echo("DN:" & objRecordSet.Fields("distinguishedName"))
Set objItem = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName")
If objRecordset.RecordCount <> 0 The
strsAMAccountName = objItem.Get("sAMAccountName"
strName = objItem.displayNam
strInfo = "
strInfo = objItem.Inf
strTelephone = objItem.Telephon
strReports = "
if len(strInfo) > 0 the
strSplit = split(strInfo,"/"
strAllowIn = trim(strSplit(0)
if Ubound(strSplit)>0 the
strReports = trim(strSplit(1))
strReports = Replace(strReports, "'", "''"
end i
end if
wscript.Echo("Adding " &lcase(strsAMAccountName) & " " & strName & " " & objItem.email
End I
End I
End Sub