# Solved: Active Directory group membership



## gjs010 (Feb 7, 2005)

I am trying to do a fairly simple exercise in which i want to list all members of an AD group. Although i can see the members no problem in the MMC, trying to get AD to print them out in some kind of order, or export the data is being trickier than i imagined. 

Surely writing a script isnt really necessary to achieve a simply request like this?
Any suggestions?


----------



## XtremeNuker (Oct 18, 2004)

Try this website it holds much of the information which you need.

http://www.activexperts.com/activmo...tivedirectory/groups/#ListActiveDirectory.htm


----------



## StumpedTechy (Jul 7, 2004)

AD has very shoddy reporting within it. I have to admit I do a ton of scripting just to get information out of AD into a reportable format. That link provided was a very good one but I want to forwarn you if your going to do more reporting your going to want to beef up your VB scripting.

Also remember if your doing - List All the Members of a Group
you may want to change around the script to instead of echo it out to output the information to a file (If you want this for reporting sake).


----------



## gjs010 (Feb 7, 2005)

thanks guys, but i got another couple of questions.
remember you are talking to a non programming guy here. firstly how do i actually run a script like below? i.e. after amending for my domain name and group name, what do i actually do with it? Secondly could you explain more fully how to output this info to a file?
Thanks in advance

_"On Error Resume Next

Set objGroup = GetObject _
("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo strMember
Next"_


----------



## jmwills (Sep 28, 2005)

You should be able to just right click the gorup and export to a .txt file is one of the options.


----------



## StumpedTechy (Jul 7, 2004)

Here is how I would do it -

On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set outfile = fso.CreateTextFile("Test.csv") <--- rename this to the file you want 
Set objGroup = GetObject _
("LDAP://") <---- set your own LDAP string you want to report on.
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

For Each strMember in arrMemberOf
outfile.WriteLine strMember <---writes each member on its own line.
Next


```
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set outfile = fso.CreateTextFile("Test.csv") 
Set objGroup = GetObject _
  ("LDAP://")
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
For Each strMember in arrMemberOf
    outfile.WriteLine strMember
Next
```
All you do is copy this I put in the "code section" to a *.txt file. add your LDAP string. Rename it to *.vbs and then run it.


----------



## gjs010 (Feb 7, 2005)

jmwills said:


> You should be able to just right click the gorup and export to a .txt file is one of the options.


dont remember that being an option - but will check tomorrow


----------



## gjs010 (Feb 7, 2005)

StumpedTechy said:


> Set outfile = fso.CreateTextFile("Test.csv") <--- rename this to the file you want


where does this actually create the file test.csv? should i be typing in a path.

Thanks for the advise stumped - i shall try this in the next couple of days.


----------



## StumpedTechy (Jul 7, 2004)

If you leave it with no path it creates it in the same dir the VBS is ran if you put a full path in there it makes it wherever you point it.

The txt export I think think that is being reffered to as the export list function of the OU itself. I have not seen where you can do an export list of an individual group. Maybe jmwills can elaborate and maybe teach us both a trick


----------



## gjs010 (Feb 7, 2005)

StumpedTechy said:


> If you leave it with no path it creates it in the same dir the VBS is ran if you put a full path in there it makes it wherever you point it.
> 
> The txt export I think think that is being reffered to as the export list function of the OU itself. I have not seen where you can do an export list of an individual group. Maybe jmwills can elaborate and maybe teach us both a trick


All that happens when you run the export is that it gives you blank headings re the OU, nothing about what users are in the group unfortunately.

I assume you can run the vbs from any pc in the domain as long as you are logging in with the appropriate rights. you dont need to be logged in the the DC


----------



## StumpedTechy (Jul 7, 2004)

Correct I run it off a network share from my own workstation when I am logged on with my admin rights ID.


----------



## Squashman (Apr 4, 2003)

Would this work with the -lu option.
http://www.joeware.net/win/free/tools/lg.htm


----------



## gjs010 (Feb 7, 2005)

thanks for the advice guys, the vbs script did the trick


----------

