' NAME: GetGroups.vbs ' v1.0 ' AUTHOR: Jeffery Hicks MCSE,MCT ' jhicks@jdhitsolutions.com ' http://www.jdhitsolutions.com ' DATE : August 2004 ' ' USAGE : cscript|wscript GetGroups.vbs ' NOTES : List all groups of a specified type in a given domain. ' License :: ' Copyright 2004 JDH Information Technology Solutions, Inc. ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 2 of the License, or ' (at your option) any later version. ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details at HTTP://www.gnu.org/licenses/gpl.txt ' ********************************************************************************* ' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB * ' * ENVIRONMENT. USE AT YOUR OWN RISK. * ' ********************************************************************************* On Error Resume Next Dim rootDSE Dim mydomain Dim conn Dim cat Dim cmd Dim rs Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h00000002 Const ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = &h00000004 Const ADS_GROUP_TYPE_LOCAL_GROUP = &h00000004 Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h00000008 Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000 sGroupScope = ADS_GROUP_TYPE_GLOBAL_GROUP or ADS_GROUP_TYPE_SECURITY_ENABLED set RootDSE=GetObject("LDAP://RootDSE") set myDomain=GetObject("LDAP://"&RootDSE.get("DefaultNamingContext")) strQuery="Select cn,distinguishedname,groupType from '" & _ myDomain.ADSPath & "' Where objectclass='group' AND GroupType='" & sGroupScope & "'" WScript.Echo strQuery set cat=GetObject("GC:") for each obj in cat set GC=obj Next AdsPath=GC.ADSPath set conn=Createobject("ADODB.Connection") set cmd=CreateObject("ADODB.Command") conn.Provider="ADSDSOObject" conn.Open set cmd.ActiveConnection=conn set RS=conn.Execute(strQuery) do while not RS.EOF wscript.Echo rs.Fields("distinguishedname") rs.movenext loop rs.Close conn.Close set conn=Nothing set cmd=Nothing set RootDSE=Nothing set cat=Nothing set RS=nothing 'EOF