Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. On Error Resume Next
  2.  
  3. Set obj = GetObject("ldap://serverip/DC=xx, DC=xx")
  4. WScript.Echo "A: " & obj.name
  5.  
  6. WScript.Echo "init script"
  7.  
  8. strUser = "TESTADAdministrador"
  9. strPass = "test"
  10. strDC = "serverip" ' this has to be FQDN of the DC
  11. strAccount = "Administrador" 'Use the sAMAccountname (logon name) value here instead of CN
  12.  
  13. Const ADS_SECURE_AUTHENTICATION = 0
  14. Const ADS_SERVER_BIND = 389
  15.  
  16. Set objDSO = GetObject("LDAP:")
  17. Set objRootDse = objDSO.OpenDSObject("LDAP://" & strDC & "/RootDSE", strUser, strPass, ADS_SECURE_AUTHENTICATION OR ADS_SERVER_BIND)
  18. strTargetDncDomain = objRootDse.Get("defaultNamingContext")
  19.  
  20. strBase = "<LDAP://" & strDC & "/" & strTargetDncDomain & ">;"
  21.  
  22. strAttrs = "cn=administrador,cn=Users,dc=xx, dc=xx"
  23. strScope = "subtree"
  24. strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAccountname=" & strAccount & "));"
  25.  
  26. strQuery = strBase & strFilter & strAttrs & strScope
  27.  
  28. Set oConnection = CreateObject("ADODB.Connection")
  29. oConnection.Provider = "ADsDSOObject"
  30. oConnection.Properties("Encrypt Password") = True
  31. oConnection.Open "Active Directory Provider", strUser, strPass
  32.  
  33. Set oCommand = CreateObject("ADODB.Command")
  34. oCommand.ActiveConnection = oConnection
  35. oCommand.CommandTimeout = 30
  36.  
  37. oCommand.CommandText = strQuery
  38.  
  39. Set objRS = oCommand.Execute
  40. Do While Not objRS.EOF
  41. strDnFound = objRS.Fields("CN")
  42. wscript.echo "found it!"
  43. wscript.echo "query: " & strQuery
  44. wscript.echo strTargetDncDomain
  45. wscript.echo strDnFound ' Just so that we know it's working
  46. objRS.MoveNext
  47. Loop
  48.  
  49. objRS.close
  50. oConnection.close
  51.  
  52. cscript.exe //NoLogo "C:pathtoyour.vbs" >"C:output.txt"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement