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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
on error resume next
dim objfichier, Myfile, Ouchoisi
const forReading = 1, ForWriting = 2, ForAppending = 8
'routine de connexion a l'AD
Const ADS_SCOPE_SUBTREE = 2
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
'choix du domaine a éxaminer
DomaineChoisi="XXX" 'inputbox ("veuillez Choisir le domaine que vous voulez inspecter","Choix du domaine")
DomaineChoisi2="local" 'inputbox ("veuillez Choisir la fin du nom de domaine que vous voulez inspecter","Choix du domaine")
OuChoisi=inputbox ("veuillez Choisir l'Unité d'organisation que vous voulez inspecter","Choix de l'OU")
'sélection de l'OU dans le domaine
objCommand.CommandText = _
"SELECT AdsPath FROM 'LDAP://OU="& OuChoisi &", dc="& DomaineChoisi &", dc="& DomaineChoisi2 &"' WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute
'création du fichier texte
set objfichier = createobject("scripting.filesystemobject")
NomFichier="test.txt" ' inputbox ("Veuillez entrez le nom de fichier","Nom du Fichier")
set Myfile = objfichier.opentextfile(NomFichier, ForWriting, true)
'boucle qui vérifie les groupes 1 par 1
'MODIFICATIONS
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
membres = ""
objMembers = objUser.GetEx("member")
For Each obj in objMembers
if not obj = "" Then
membres = Membres & ";" & obj
End If
Next
Myfile.Writeline objUser.sAMAccountName & membres
objRecordSet.MoveNext
Loop
'message de fin d'éxecution du script
MsgBox "votre recherche dans l'AD est terminée", vbExclamation, "Avertissement" |
Partager