Bonjour,
Je souhaite créer un script qui me permette de lister l'ensemble des utilisateurs d'une OU.
J'ai commencé en m'inspirant d'un code similaire mais qui liste les utilsateurs des groupes.
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
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
Function CreateAfile(resumeFile)
   Dim fso, MyFile 'fso pour File System Object
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set MyFile = fso.CreateTextFile(resumeFile, True)
End Function
 
Function WriteText(MyFile,myText)
   Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
   Dim fso, f, ts
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(MyFile)
   Set ts = f.OpenAsTextStream(ForAppending, TristateUseDefault)
   ts.WriteLine myText
   ts.Close
End Function
 
 
Dim objADAM    ' Binding object.
Dim objOU   ' Group object.
Dim objMember  ' Member object.
Dim strPath    ' Binding path.
Dim strOU      ' OU à renseigner
Dim i 
i = 0
 
' Construct the binding string.
strOU = inputbox("Entrez le chamin LDAP de l'OU: " & vbcrlf & "ex : OU=monOU,DC=monDC")', tb)
strPath = "LDAP://" & strOU
 
WScript.Echo "Bind to: " & strPath
WScript.Echo "Enum:    Groups and members"
 
RecapFile = "D:\Mes Documents\Scripts\AD Utils\Members" & RecupOuName(strOU) & ".txt"
CreateAfile(RecapFile) 
 
' Bind to object.
Set objADAM = GetObject(strPath)
 
' Enumerate groups and members.
objADAM.Filter = Array("organizationalUnit")
For Each objOU in objADAM
	WriteText RecapFile, vbcrlf & "Organizational-Unit: " & objOU.canonicalName & vbcrlf & "Members :"
    For Each objMember in objOU.Members
		WriteText RecapFile, Mid(objMember.Name, 4)
		objMemberOf  = objMember.GetEx("memberOf" ) 
		For Each objGroup2 in objMemberOf  
			i = i + 1
		Next
    Next
Next
 
WScript.echo "fin du traitement"
function RecupOuName(Text)
Dim i,tb
tb = split(Text,",")
RecupOuName = tb(0)
end function
Mon pb c'est que la méthode : N'exite pas pour les OU seulement pour les group!
Quelqu'un aurait il une idée de comment je peux faire?
Merci par avance.