Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15621

Searching Active Directory Sub OU's with script

$
0
0
I have an old vbs script that I'd like to reuse versus rewrite. It works, but it's not able to search sub OU's using LDAP search.
It does use a csv as a validation script file, and that part works fine.
I have a feeling this is an easy fix to make it search resursively. Any assistance would be much appreciated.
Without giving too much private information away:

Sub DumpLDAPUserInfo
Dim MyiOUcnt
Dim MyioUsercnt
Dim MyarrCols
Dim MysKey
Dim MysEmail
' Insert code securely
sLDAPServer = "test.com"
sUser = "testuser"
sPassword = "Password1"
sCN = "/CN=" & sUser
sDN = "CN=" & sUser & "OU=Users,OU=Corporation,DC=Test,DC=com"
sOUDNQuery = "LDAP://test.com/OU=Users,OU=Corporation,DC=Test,DC=com"

Set oDS = GetObject("LDAP:")
Set oOUDN = oDS.OpenDSObject( _
sOUDNQuery, _
sUser, _
sPassword, _
ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
sMsg = oOUDN.Class & vbCrLf & sOUDNQuery & vbCrLf & _
"Click OK to Continue ..."
Call DisplayMsg(sMsg,5,vbInformation)
MyiOUcnt = 0
MyioUsercnt = 0
sLastCN = ""
For each oOU in oOUDN
MyiOUcnt = MyiOUcnt + 1
MysKey = oOU.cn
If dictValidation.Exists(MysKey) Then
MyarrCols = Split(dictValidation(MysKey),"|")
sEmplID = MysKey
sFirstName = MyarrCols(10)
sLastName = MyarrCols(11)
sEmail = MyarrCols(9)
MysEmail = oOU.mail
If (oOU.mail <> "") AND (lcase(oOU.mail) <> lcase(sEmail)) Then
' If MyioUsercnt < 10 Then
' sMsg = oOU.cn & vbCrLf & _
' oOU.displayName & vbCrLf & _
' oOU.givenName & vbCrLf & _
' oOU.sn & vbCrLf & _
' oOU.mail & vbCrLf & _
' "Old email: " & sEmail
' Call DisplayMsg(sMsg,2,vbInformation)
' End If
Call WriteOutput
MyioUsercnt = MyioUsercnt + 1
End If
sLastCN = oOU.cn
End If
Next
sMsg = "oOU count=" & CStr(MyiOUcnt) & vbCrLf & _
"oUser count=" & Cstr(MyioUsercnt) & vbCrLf & _
"Output count=" & Cstr(iOutcnt)
End Sub

Viewing all articles
Browse latest Browse all 15621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>