Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


ad group enumeration question/bug found

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,52369
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> ad group enumeration question/bug found
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 ad group enumeration question/bug found - 10/2/2007 1:39:29 AM   
  faulkkev

 

Posts: 151
Score: 0
Joined: 11/1/2005
Status: offline
I have a working group membership script which has worked fine or so it appeared.  I recently noticed if a users primary group isn't domain users it will not enumerate them.  Any ideas as to why this is?  I have tested this with a dummy account.  I would think most home groups would be domain users so the accounts may be incorrect but I don't understand why the script cares and ignores them..

errorlog = "c:\members.txt"
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objfile = objfso.CreateTextFile(errorlog, True)
on error resume next
Dim intCount, strGroup, strDomain, oGroup, oMember,objgroup

strGroup = InputBox("Group to query?")

gdn= SearchGroup(strgroup)
Set iAdRootDSE = GetObject("LDAP://RootDSE")
   sDomainName = iAdRootDSE.Get("defaultNamingContext")

if err.number <> 0 then
objfile.writeline now & " Error Group Not bound to "
else
objfile.writeline " Group Being Enumerated is " & strgroup & " " & intGroupType & "         DOMAIN IS " & sdomainname
objfile.writeline ""
end if


GetMembers(gDN)
Function GetMembers(gDN)

set objGroup = GetObject("LDAP://" & gdn)
objgroup.getinfo


For Each oMember in objgroup.members
intCount = intCount + 1
on error resume next
       ObjDisp = oMember.Name
       oDL = Len(ObjDisp) - 3
       ObjDisp = Right(ObjDisp,oDL)
       ObjCatArray = Split(oMember.class,",")
       oType = ObjCatArray(0)
       oTL = Len(oType) - 3
       oType = Right(oType,oTL)

if lcase(omember.class) = "computer" then
  objfile.writeline now & " Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type: Computer"
end if 
  if lcase(omember.class) = "contact" then
   objfile.writeline now & " Member: " & ObjDisp & Space(30-Len(ObjDIsp)) & " Type:Contact"
  end if
   if lcase(omember.class) = "user" then
    objfile.writeline now & " Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:User" & " " & omember.fullname
  end if
' if fullname not available or blank
if err.number = "-2147463155" and omember.class <> "group" then
     objfile.writeline now & " Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:User"
end if
if lcase(omember.class) = "group" then
objfile.writeline " "
objfile.writeline "***********************Nested Group*******************************************" 
 
       objfile.writeline now & " Nested Group : " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:group"
       objfile.writeline " "
       sgroup = objdisp
       sgetmembers(sgroup)
objfile.writeline "***********************End Of Nested Group*******************************************"
objfile.writeline " "
      
   end if
Next
if intcount <> 0 then
objfile.writeline " "
objfile.writeline  " The " & strGroup & " Has " & intcount & " Members "
else
objfile.writeline now & " The " & strgroup & " has " & " 0 " & " Members "
end if

Set oMember = Nothing
set objdisp = nothing  
err.clear
end function
'*************************************END FUNCTION***************************************
objfile.writeline ""
objfile.writeline " All " & strgroup & " members " & "have been written to c:\members.txt file "


'**************************************FUNCTION SEARCHGROUP********************************
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
   SearchGroup = oRecordSet.Fields("distinguishedName")
   ocommand.Properties("Page Size") = 1000
   ocommand.Properties("Timeout") = 30
   ocommand.Properties("Cache Results") = False
   On Error GoTo 0
   oConnection.Close
   Set oRecordSet = Nothing
   Set oCommand = Nothing
   Set oConnection = Nothing
   Set oRootDSE = Nothing
End Function
'*********************************End Function********************************************

'********************************FUNCTION SGETMEMBERS*************************************
function sgetmembers(sgroup)
gdn= SearchGroup(sgroup)

set sobjGroup = GetObject("LDAP://" & gdn)
sobjgroup.getinfo


For Each soMember in sobjgroup.members
on error resume next

       ObjDisp = soMember.Name
       oDL = Len(ObjDisp) - 3
       ObjDisp = Right(ObjDisp,oDL)
       ObjCatArray = Split(soMember.class,",")
       oType = ObjCatArray(0)
       oTL = Len(oType) - 3
       oType = Right(oType,oTL)
if lcase(omember.class) = "computer" then
  objfile.writeline now & " Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type: Computer"
end if 

if lcase(somember.class) = "contact" then
objfile.writeline now & " Member: " & ObjDisp & Space(30-Len(ObjDIsp)) & " Type:Contact"
end if
if lcase(somember.class) = "user" then
objfile.writeline now & " Nested Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:User" & " " & somember.fullname
end if
' if fullname not available or blank
    if err.number = "-2147463155" and somember.class <> "group" then
    objfile.writeline now & " Nested Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:User"
end if
   
if lcase(somember.class) = "group" then

objfile.writeline " "
objfile.writeline "***********************Sub Nested Group of " & sobjgroup.name & " *******************************************"


  objfile.writeline now & " Sub Nested Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:Group"
  objfile.writeline " "
   objdisp= somember
    sgetmembers(objdisp)
    
   objfile.writeline "***********************End Of Sub Nested Group*******************************************"
   objfile.writeline " "
    

end if
 


next

set objdisp = nothing
set somember = nothing
err.clear
end function
'**************************************FUNCTION END******************************************



objfile.close
result = objfso.OpenTextFile(errorlog, 1).ReadAll
wscript.echo result
 
 
Post #: 1
 
 RE: ad group enumeration question/bug found - 10/2/2007 2:09:57 AM   
  LANlazy

 

Posts: 82
Score: 0
Joined: 4/11/2007
Status: offline
First I thought it was due to ObjDIsp instead of your Space line reading ObjDisp but that did not fix it.  So I removed all the on error resume next and it errored on line 46 char 5 which is the Space.  So I changed it and it seems to work now.  I dont know why it did not like the -Len(ObjDIsp)

objfile.writeline now & " Member: " & ObjDisp & Space(20-Len(ObjDIsp)) & " Type:User" & " " & omember.fullname

to

objfile.writeline now & " Member: " & ObjDisp & Space(20) & " Type:User" & omember.fullname


(in reply to faulkkev)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> ad group enumeration question/bug found Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts