1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Const ADS_SCOPE_SUBTREE = 2
Set Root = GetObject("LDAP://RootDSE")
DomainPath = Root.Get("DefaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "<LDAP://" & DomainPath & ">;(&(objectCategory=person)(objectClass=user)); sAMAccountName,employeeid ;subtree" //C'est là qu'il me faut des champs
Set objRecordSet = objCommand.Execute
a="SAM_Account_Name;Employe_ID"
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
a = a & vbnewline & objRecordSet.Fields("sAMAccountName") & ";" & objRecordSet.Fields("employeeid")
objRecordSet.MoveNext
Loop
Set fs = CreateObject("Scripting.FileSystemObject")
Set fich = fs.OpenTextFile("C:\log.txt", 2, true)
fich.write a
fich.close
msgbox "OK" |