'LDAP Query Script
'v1.0
'Written By Lee Mason
'Purpose: Uses ADSI To Query an OU and its subcontainers for users that are
'NOT members of a specified group
'then writes out to a text file.
'---------------------------------------------------------------------------------------
Option Explicit
'Declare and obtain Variables
Dim ObjLocation
Dim ObjMember
Dim ObjGroup
Dim FilOutputMembers
Dim FilOutputNonMembers
Dim fso
Dim ObjectType
Dim arrSubContainers(4)
dim i
dim strtargetgroup 'the group you want to find
dim strtoplevelOU 'the first part of your domain, ie for "mycompany.co.uk", this
would be "mycompany"
dim strsecondlevelOU 'co
dim strthirdlevelOU 'uk
'add more in here if you need them - don't forget to add them to the getobject
statement below!
'enumerate subcontainer names in an array for looping through
ObjectType = "<subOU1>"
arrsubcontainers(0) = "<subOU2>"
arrsubcontainers(1) = "<subOU3>"
arrsubcontainers(2) = "<subOU3>"
arrsubcontainers(3) = "<subOU4>"
'set reference to PC-Duo Group
set ObjGroup = GetObject("LDAP://cn=" & strtargetgroup & ",ou=" & strtoplevelOU
& ",ou=" & strsecondlevelOU & ",dc=" & strthirdlevelOU)
'Instantiate Output Files using FilesystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
Set FilOutputMembers = fso.CreateTextFile("\\springboardha.org.uk\dfs\track-IT\Reporting\Group
Lists\" & Objgroup.name & " Members.txt", True)
With FiloutputMembers
.WriteLine("Member List")
.writeline("------------------------------------------------------")
.writeline("Generated " & Date())
.writeline(" ")
End With
Set FilOutputNonMembers = fso.CreateTextFile("\\springboardha.org.uk\dfs\track-IT\Reporting\Group
Lists\" & Objgroup.name & " NonMembers.txt", True)
With FiloutputNonMembers
.WriteLine("Non-Member List")
.writeline("------------------------------------------------------")
.writeline("Generated " & Date())
.writeline(" ")
End With
'Bind to Ads group for each subcontainer
for i=0 to 4
'Set reference to teh subcontainers contained in the array
Set objLocation = GetObject("LDAP://ou=" & arrsubcontainers(i) & ",ou=" &
Objecttype & strtoplevelOU & ",dc=" & strsecondlevelOU & ",dc=" &
strthirdlevelOU)
MsgBox ObjLocation.name
'test for membership and write result out to appropriate file
For Each ObjMember In ObjLocation
If ObjGroup.IsMember("LDAP://" & ObjMember.name & ",ou=" & arrsubcontainers(i) &
",ou=" & Objecttype & ",dc=" & strsecondlevelOU & ",dc=" & strthirdlevelOU) Then
filoutputMembers.WriteLine(arrsubcontainers(i) & " " & ObjMember.name)
Else
filoutputNonMembers.WriteLine(arrsubcontainers(i) & " " & ObjMember.name)
End If
next
next
Monday, January 23, 2006
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment