Windows Server 2003
cancel
Showing results for 
Search instead for 
Did you mean: 

AD Script to search and list members

 
Highlighted
kuvinod
Occasional Visitor

AD Script to search and list members

Hi,

We have 100+ groups in our Active Directory. Iam trying to write an script which will prompt the user for an group name to be searched inside the AD and then displays the members of the group ? Can this be achieved by script? If so can someone please help.

Regards
RVK
1 REPLY 1
Robert Walker_8
Valued Contributor

Re: AD Script to search and list members

Gday,

Yes relatively easy to do (via ADSI - could also look at powershell) depends upon ou's or whatever and how you have layed out your Active Directory. There are two ways use WinNT provider (may be problematic if AD is running Win2003 Native Mode) or LDAP provider. Here is some simple code which can be built upon.

WinNT:
cut below into file called script.vbs put in your domain controller and test group and run - cscript script.vbs

--------------------------

agroup = ""
aserver = ""
set x = getobject("WinNT://" & aserver & "/" & agroup & ",group")
for each entry in x.members
if ucase(entry.class) = "USER" then
wscript.echo entry.name
end if
next
set x = nothing

--------------------------

LDAP:

Unfortunately LDAP requires precise location of group (eg: ou=sales,dc=microsoft,dc=com or cn=groups, dc=microsoft, dc=com). Your dns forest/domain name make up the DC aspect of the lookup thus server1.yahoo.com.au is server1=dc,dc=yahoo, dc=com, dc=au etc.

If you have different OUs such as SALES, HR etc and groups within that then you have

cn=yourgroup, ou=SALES, dc=

or

cn=yourgroup, ou=HR, dc=

Then you can do a similar thing as above but use LDAP instead of WinNT.

--------------
agroup = "cn=,ou=sales"
adomain = "dc=yahoo,dc=com,dc=au"
aserver = ""
set x = getobject("LDAP://" & aserver & "/" & agroup & "," & adomain)
for each entry in x.members
if entry.class = "User" then
wscript.echo entry.samaccountname
end if
next
set x = nothing
----------------