Bonjour, je ne comprend pas trop ce qu'il se passe:/


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Const ADS_SCOPE_SUBTREE = 2
Set sh = CreateObject("WScript.Shell")
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
groupOrUser = "user"
strUserSAMAccountName = "u/Toto23654"
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
FichierTXT = "CheminLDAP_de_" & strUserSAMAccountName & ".txt"
Set TxtOutput = fso.CreateTextFile(FichierTXT,TRUE)
 
objCommand.CommandText = "SELECT * FROM 'LDAP://" & GetObject("LDAP://RootDSE").Get("DefaultNamingContext") & "' WHERE objectClass='" & groupOrUser & "' AND sAMAccountName = '" & strUserSAMAccountName &"'"
Set objRecordSet = objCommand.Execute
If Not objRecordSet.EOF Then
	for each toto in objRecordSet.Fields
		TxtOutput.WriteLine(toto)
		Wscript.echo(toto)
		Wscript.echo("------------")
	next
Else
	TxtOutput.WriteLine("Utilisateur <" & strUserSAMAccountName & "> non trouvé")
End If
Set fso = Nothing
sh.Run("CheminLDAP_de_" & strUserSAMAccountName & ".txt")
Set sh=Nothing
Je sélectionne donc TOUTES les infos du compte qui est un user et est mon utilisateur, et je fait un for each pour tous lister, simplement, il ne me donne QUE le distinguishedName ou le ADSPATH (je ne sait plus).

Donc j'ai essayer avec

Code : Sélectionner tout - Visualiser dans une fenêtre à part
objCommand.CommandText = "SELECT objectCategory, Name, distinguishedName, sAMAccountName, displayName, telephoneNumber, givenName, mail, canonicalName, cn, compagny, description FROM 'LDAP://" & GetObject("LDAP://RootDSE").Get("DefaultNamingContext") & "' WHERE objectClass='" & groupOrUser & "' AND sAMAccountName = '" & recupSamName &"'"
mais il plante sur certains élément notamment le canonicalName que je n'arrive pas à afficher.

Merci pour m'avoir lu.
Cordialement.