Ik moet van een OU in de AD een export maken van alle globale groepen die geen members bevat.
In het verleden heb ik een mooi vbscript gevonden wat wel van de volledige AD een export kan maken. Maar ik heb geen idee hoe ik dit kan aanpassen zodat het toepasbaar zou zijn voor 1 bepaalde OU.
Of heeft mogelijk iemand anders een prima oplossing?
Ik heb sterk getwijfeld in welk onderdeel ik dit moest posten. Hopelijk zit ik hier bij de juiste mensen
In het verleden heb ik een mooi vbscript gevonden wat wel van de volledige AD een export kan maken. Maar ik heb geen idee hoe ik dit kan aanpassen zodat het toepasbaar zou zijn voor 1 bepaalde OU.
Of heeft mogelijk iemand anders een prima oplossing?
Ik heb sterk getwijfeld in welk onderdeel ik dit moest posten. Hopelijk zit ik hier bij de juiste mensen
code:
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
68
69
70
71
72
73
74
75
76
77
78
| 'VBScript to output to text file the members of all groups
On Error Resume Next
Set objArgs=wscript.Arguments
If objArgs(0)<>"-dn" Then
wscript.echo "Dumping group membership using full DN..."
Else
wscript.echo "Dumping group membership using only first CN part..."
End If
'Stuff for creating output text file
Const OutputFile = ".\groupdump.txt"
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Wshshell = Wscript.CreateObject("Wscript.Shell")
Set Output = Fso.OpentextFile(OutputFile, 2, True)
Set ADSIRootDSE = GetObject("LDAP://RootDSE")
ADSINamingNC = ADSIRootDSE.Get("rootDomainNamingContext")
Set ADSIConnection = CreateObject("ADODB.Connection")
ADSIConnection.Provider = "ADsDSOObject"
ADSIConnection.Open "ADs Provider"
ADSIQueryText = "<LDAP://" & ADSINamingNC & ">;(&(objectCategory=group));name,distinguishedName;subtree"
Set ADSICommand = CreateObject("ADODB.Command")
Set ADSICommand.ActiveConnection = ADSIConnection
ADSICommand.CommandText = ADSIQueryText
ADSICommand.Properties("Page Size") = 100
ADSICommand.Properties("Timeout") = 60
ADSICommand.Properties("searchscope") = 2
ADSICommand.Properties("Cache Results") = False
Set ADSIResult = ADSICommand.Execute
Do While not ADSIResult.EOF
Output.WriteLine
Output.WriteLine
Output.WriteLine "Group: " & ADSIResult.Fields("name").Value
Output.WriteLine "==============================================================="
Set GetDN = GetObject("LDAP://" & ADSIResult.Fields("distinguishedName").Value)
strAllValues = GetDN.GetEx("member")
iGroupCount = 0
For each strValue in strAllValues
If Len(strValue) = 0 Then
Output.WriteLine "There are no members in this group."
Else
iGroupCount = iGroupCount + 1
If objArgs(0)<>"-dn" Then
Output.WriteLine strValue
Else
Call Stripper(strValue)
Output.WriteLine tmp
End If
End If
Next
Output.WriteLine "Total members in group: " & iGroupCount
Set strAllValues = Nothing
ADSIResult.MoveNext
Loop
Output.Close
wscript.echo "Operation has finished."
Wscript.quit
Function Stripper(StripperString)
pos = InStr(1, StripperString, "cn=", vbTextCompare)
If pos <> 0 Then
tmp = Mid(StripperString, pos + 3)
pos = InStr(tmp, ",")
If pos <> 0 Then tmp = Mid(tmp, 1, pos - 1)
End If
End Function |