List Groups in AD using vbscript

Is there a way to list all groups in Active Directory using vbscript? More specifically Distribution Groups?
Javier_GAsked:
Who is Participating?
 
moduloCommented:
PAQed with points refunded (125)

modulo
Community Support Moderator
0
 
Shane Russell2nd Line Desktop SupportCommented:
What about this :

' Get the name of the computer
str_Computer = WScript.CreateObject("WScript.Network").ComputerName

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oOutFile = oFSO.CreateTextFile("c:\usersandgroups.txt")

' Connect to the computer object
set oMachine = getObject("WinNT://" & str_Computer & ",computer")

' Set the filter to list users
oMachine.Filter = Array("group")

' For each group on the machine
For Each oGroup in oMachine
  oOutFile.writeline oGroup.Name

  ' For each user in the group
  For Each oUser in oGroup.Members
    ' display the user name
    oOutFile.writeline  vbTab & oUser.Name
  Next
Next

oOutFile.Close

Set oOutFile = Nothing
Set oFSO = Nothing
0
 
Javier_GAuthor Commented:
I believe this would display local groups not Active Directory Groups.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Shane Russell2nd Line Desktop SupportCommented:
0
 
Shane Russell2nd Line Desktop SupportCommented:
More precisely the site from the above one to do what you want is :

http://cwashington.netreach.net/depo/view.asp?Index=1037&ScriptType=vbscript
0
 
Javier_GAuthor Commented:
I thought we were there.....That script works great but it displays the exact opposite of what I wanted. It only lists security groups, what I need is distribution groups.
0
 
Javier_GAuthor Commented:
Here it is:

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
    "SELECT ADsPath FROM 'LDAP://dc=domain,dc=com' WHERE objectCategory='group' "
   
Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Set objType = GetObject(objRecordSet.Fields("ADsPath").Value)
        If objType.GroupType > 0  Then
            Wscript.Echo "Group: " & objType.cn
        End If
    objRecordSet.MoveNext
Loop

If you make the GroupType < 0 then it will display only security groups.
0
 
Shane Russell2nd Line Desktop SupportCommented:
what are you doing with this question then, also did the URL I posted help in anyway what so ever or you just going to close this question out now ?
0
 
Javier_GAuthor Commented:
What you had posted was not what I needed. In my initial question I was asking for enumerating specifically distribution groups.

I would like this question to be closed now.

0
 
sr75Commented:
You can close it after you test my script.  Of course you will need to edit it to reflect you domain.

<><>Begin Script<><>

On Error Resume Next

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

set DomainOU = GetObject("LDAP://cn=users,dc=domain,dc=COM")

DomainOU.Filter = Array("group")

For each objGroup in DomainOU
      strGroup = objGroup.cn
      set objGroup = GetObject("LDAP://cn=" & strGroup & "cn=users,dc=domain,dc=COM")
      objGroup.GetInfo
      intGroupType = objGroup.Get("groupType")

      If intGroupType AND ADS_GROUP_TYPE_SECURITY_ENABLED then
            List = List
      else
              List = List & strGroup & vbtab & "Distribution group" & vbCrLf
      End If
next

wscript.echo List

<><>end script<><>
0
 
Javier_GAuthor Commented:
I had already answered the question myself. I would like the points refunded.
0
 
VenabiliCommented:
Please post your solution. Otherwise I will recommend no points refunded for ignoring the last expert comment.
0
 
Javier_GAuthor Commented:
I already posted it on Date: 04/29/2005 03:36PM PDT, it starts out with "Here it is:". Read above.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.