Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tool for listing groups, users 1

Status
Not open for further replies.

EGR

Technical User
Feb 18, 2002
159
DE
Hi,

I'm searching for a tool.
It should list all groups with members of my server 2003 system.
Furthermore it should be able to to write the result into a textfile.
I couldn't find it in the ressource kit.
Do you have any hints?

Thanky you.
/noodles
 
Here you go.

Code:
Option Explicit
Dim aCon, aCMD,aRst,sResultText,Grps,MemberList
Set aCon = CreateObject("ADODB.Connection")
Set aCmd = CreateObject("ADODB.Command")

aCon.provider="ADsDSOObject"
aCon.Open
aCmd.ActiveConnection = aCon

'******************************************************************************
'******************************************************************************
'CUSTOMIZE THE NEXT TWO LINES
aCmd.CommandText="<LDAP://CN=Users,DC=YourComany,DC=com>;" & "(objectClass=group);name,SamAccountName"
dom = "YourDomainName"
'******************************************************************************
'******************************************************************************


Set aRst = aCmd.Execute()
Do While Not aRst.EOF
	sResultText = sResultText & aRst.Fields("samAccountName") & vbCrLf
	'WScript.Echo aRst.Fields("samAccountName") & vbCrLf
	MemberList=RetrieveUsers(dom,aRst.Fields("samAccountName"))
	'WScript.Echo Memberlist
	sResultText = sResultText & memberlist & vbCrLf & "************************************" & vbCrLf
	
	aRst.MoveNext
Loop
'Wscript.Echo sResultText

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile (dom & "DomainGroupUsers.txt", ForWriting)
ts.write sResultText
MsgBox "Done"


'*****************************************************************************************
'*****************************************************************************************
Function RetrieveUsers(domainName,grpName)

dim dom
dim grp
dim GrpObj
dim mbrlist
dim mbr

'-------------------------------------------------------------------------------
' *** Enumerate Group Members ***
'-------------------------------------------------------------------------------

grp = grpName

' Build the ADSI query and retrieve the group object
Set GrpObj = GetObject("WinNT://" & domainName & "/" & grp & ",group")

' Loop through the group membership and build a string containing the names
for each mbr in GrpObj.Members
   mbrlist = mbrlist + "    " &mbr.name + vbCrLf
Next

'The next line returns mbrlist back up to the main body
RetrieveUsers=mbrlist

End Function

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
usrstat polls users from the SAM
netgroups polls group lists
netgroups /showmbrs polls groups and members
 
Hi Mark!

Thank you for the answer! Excuse my late reaction.
I'm not very firm with scripting.

It doesn't seem to work. I inserted our information but when executing the vbs-script the error appears that in line 14 variable 'dom' is not defined.


Any ideas?
/egr
 
Hi Mark!!

It works!
I read a bit about vbs and defined missing variables.
Your Script works really fine!

Thank you very very much!

/egr
 
You are welcome. Have fun with it.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top