From: "Peña, Botp" Date: 2007-04-25T11:12:40+09:00 Subject: Re: Retrieving Groups from a DSQUERY From: anon1m0us [mailto:anon1m0us@yahoo.com] : # I need a list of all the groups a user is part of. When I do the # DSQuery in returns a bunch of groups. I need to capture the group # names. # All groups start with CN=group name and end with a comma. # How to I capture the group name only, which starts after CN= and ends # at the FIRST comma?? small world ;) look into "dsquery group" and "dsget group -members" C:\family\ruby\win-ds-groups>cat test.rb ####################### # botp # updated: 2007 03 21 ####################### # get all internet groups w names like "internet mail or internetusers" groups=`dsquery group -limit 1000 | egrep -i "internet(users| mail)"` len = groups.max.length + 20 # not important; just want to get length for header line separator # display groups and the count groups.each_with_index do |g,i| puts "-"*len puts "Group #{i+1}: #{g}" puts "-"*len # for each group get the members members = `dsget group #{g} -members` # for each member display name and the count members.each_with_index do |m,i| name = m.sub ",CN=Users,DC=delmonte-phil,DC=com\"", "" name = name.sub "\"CN=", "" name = name.sub "\\", "" puts "#{i+1}: #{name}" end end #------------------ hth. kind regards -botp