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

enumerate groups a computer is in

Status
Not open for further replies.

AntunB

IS-IT--Management
Aug 11, 2003
263
AU
How woult i be able to enumerate all the groups a single computer is on the domain?


i am able to get the groups a user is in but not computer using this code

------------------------------------------------
Set user = Getobject("WinNT://domain/username,user")
For Each Grp in user.groups
ListGroups = ListGroups & Grp.name & vbtab
Next
msgbox ListGroups
------------------------------------------------

I thought i could change it but this didnt work, it just listed local groups, and not ones on the domain
any one know how i can do this>?

------------------------------------------------
Set user = Getobject("WinNT://domain/computername,computer")
MyComputer.Filter = Array("group")
For Each Grp in user
ListGroups = ListGroups & Grp.name & vbtab
Next
msgbox ListGroups
------------------------------------------------



Thanks

 
Ok i sort of worked it out if i use LDAP:// instead o WinNT:// it sort o works

Set user = GetObject("LDAP://CN=ComputerName,OU=Computers,OU=Root,DC=Domain,DC=Com")
For Each Grp in user.groups
ListGroups = ListGroups & Grp.name & vbtab
Next
msgbox ListGroups

However what if i have a computer in a different OU, i cant use the same script for all OU's?????

say i have a computer in
LDAP://CN=ComputerName,OU=Other,OU=Computers,OU=Root,DC=Domain,DC=Com
note the "OTHER" OU, the top bit wont work,


so is theer something that will go through all OU's or something?

Thanks
 
In faq329-5688 you will find a function to get the Distinguished Name of a user/computeraccount.

You can add this in your code:

Code:
Set Computer = GetObject("LDAP://" & SearchDistinguishedName (ComputerName & "$"))
For Each Grp in Computer.groups
    ListGroups = ListGroups & Grp.name & vbtab
Next
msgbox ListGroups

Does this work?

Please tell me if I'm wrong I like to learn from my mistakes...
_____________________________________
Feed a man a fish and feed him for a day.
Teach a man to fish and feed him for a lifetime...
 
I get an error

Line:
Code:
Set Computer = GetObject("LDAP://" & SearchDistinguishedName (ComputerName & "$"))
Char: 1
Error: 0x80005000
Code: 80005000
Source: (null)
 
Ok it works for usernames and not for computers.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top