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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding to WIndows 2000 Objects in VBSCRIpt

Status
Not open for further replies.

craizie11

MIS
Mar 18, 2004
14
0
0
US
i'm trying to bind to the administrators group using VB Script.
I'm trying to find out who the administrators are in my domain.

my domain is television.njoy.com

and my domain controller is: babylon

the code i'm using is:
ObjOU = GetObject"LDAP://babylon.television.njoy.com/OU=Administrators")

can anyone helpme with the code
 
Your administrators group would be a CN not an OU.

Give this a try, it will report all of your group memberships for you.

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
aCmd.CommandText="<LDAP://CN=Users,DC=television,DC=njoy,DC=com>;" & "(objectClass=group);name,SamAccountName"

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

aRst.MoveNext
Loop
Wscript.Echo sResultText



'*****************************************************************************************
'*****************************************************************************************
Function RetrieveUsers(grpName)

dim dom
dim grp
dim GrpObj
dim mbrlist
dim mbr

'-------------------------------------------------------------------------------
' *** Enumerate Group Members ***
'-------------------------------------------------------------------------------
dom = "television"

grp = grpName

' Build the ADSI query and retrieve the group object
Set GrpObj = GetObject("WinNT://" & dom & "/" & 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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top