Option Explicit
Dim MyDistinguishedName
Dim objRootDSE, objItem, objConnection, objCommand, objRecordSet
Dim strContainer, strname
Dim intCounter
strContainer = "" 'Si vous souhaitez vous connecter à une OU en particulié, indiquez la ici
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_SCOPE_SUBTREE = 2
On Error Resume Next
Set objRootDSE = GetObject("LDAP://rootDSE")
If strContainer = "" Then
Set objItem = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext"))
Else
Set objItem = GetObject("LDAP://" & strContainer & "," & _
objRootDSE.Get("defaultNamingContext"))
End If
On Error Goto 0
'strname = objItem.Get("name")
'WScript.Echo "name: " & strname
MyDistinguishedName = objItem.Get("distinguishedName") 'Récupération du distinguishedName du domaine par défaut. Exemple DC=Cotonso,DC=Com
'WScript.Echo "distinguishedName: " & MyDistinguishedName
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = "<LDAP://" & MyDistinguishedName & ">;(objectCategory=Group);name,cn,displayName,sAMAccountName,distinguishedName,member;subtree"
objCommand.Properties("Page Size") = 10000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
intCounter = 0
Do Until objRecordset.EOF
'WScript.echo objRecordset.Fields("distinguishedName")
WScript.echo "Name : " & VbTab & objRecordset.Fields("Name")
WScript.echo VbTab & "cn : " & VbTab & objRecordset.Fields("cn")
WScript.echo VbTab & "displayName : " & VbTab & objRecordset.Fields("displayName")
WScript.echo VbTab & "sAMAccountName : " & VbTab & objRecordset.Fields("sAMAccountName")
WScript.echo VbTab & "distinguishedName : " & VbTab & objRecordset.Fields("distinguishedName")
objRecordset.MoveNext
Loop
objConnection.Close
Lien vers le fichier : cliquez ici
Article(s) suivant(s)