Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerate Nested Group Members

Status
Not open for further replies.

prz130

MIS
Mar 31, 2008
2
US
I have a working vbscript that accomplishes part of my goal but not all of it. The goal of the script is to be given a group name and to pull the user's name, userid, and email from the group and all nested groups. The script I have will retrieve the information, but does not do it for nested groups. How do I do this with this script or a new one?

Thanks

Dim strDN
Dim regEx, Match, Matches
Dim objFSO, objOutFile

If (Wscript.Arguments.Count < 1) Then
Wscript.Echo "Required argument <Group Name> is missing."
Wscript.Quit(0)
End If

Set regEx = New RegExp
regEx.Global = true
regEx.IgnoreCase = True

strDN = Wscript.Arguments(0)
gDN = SearchGroup(strDN)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutFile = objFSO.OpenTextFile(".\" & strDN &".log", 8, True)

GetMembers(gDN)
Function GetMembers(gDN)
Set objGroup = GetObject("LDAP://" & gDN)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")

For Each strMember in arrMemberOf
Set objMember = GetObject("LDAP://" & strMember)
ObjDispName = objMember.name
ObjDispSAM = objMember.samAccountName
ObjDispMail = objMember.mail

regEx.Pattern = "\\"
ObjDispName = Trim(regEx.Replace(ObjDispName, ""))
regEx.Pattern = "CN="
ObjDispName = Trim(regEx.Replace(ObjDispName, ""))

objOutFile.WriteLine ObjDispName & ", " & ObjDispSAM & ", " & ObjDispMail

End Function

Public Function SearchGroup(ByVal vSAN)
Dim oRootDSE, oConnection, oCommand, oRecordSet
Set oRootDSE = GetObject("LDAP://rootDSE")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
">;(&(objectCategory=Group)(samAccountName=" & vSAN & "));distinguishedName;subtree"
Set oRecordSet = oCommand.Execute
On Error Resume Next
SearchGroup = oRecordSet.Fields("distinguishedName")
On Error GoTo 0
oConnection.Close
Set oRecordSet = Nothing
Set oCommand = Nothing
Set oConnection = Nothing
Set oRootDSE = Nothing
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top