Enumerate objects within Domain Computers?

i want to be able to loop through all of the computers within Domain Computers.  when i run the code listed, it will successfully work for every me-created group (e.g. myTestComputerGroup, etc) but when i run it against, Domain Computers, I get:  "The directory property cannot be found in the cache."  So i ran Active Directory Explorer to see the differences and they are apparently striking.  Normal groups keep a list of their members in an attribute called "member."  However, my Domain Computers group does not have a "member" attribute and from Active Directory Explorer I can even tell what computers are in it (and yes, there are some).  Does anyone know why this is or how I can loop through all of the computers in Domain Computers?  ADUC can obviously do it...  o.O
Option Explicit
Dim strMember, strDNSDomain, strContainer
Dim objGroup, objRootDSE
Dim arrMemberOf
 
strContainer = "cn=Domain Computers,cn=Users, "
Set objRootDSE = GetObject("LDAP://rootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
 
WScript.Echo "LDAP://"& strContainer & strDNSDomain
 
Set objGroup = GetObject("LDAP://"& strContainer & strDNSDomain)
objGroup.getInfo
 
arrMemberOf = objGroup.GetEx("member")
 
WScript.Echo "Members of Group " & strContainer
For Each strMember in arrMemberOf
   WScript.echo strMember
Next
 
Wscript.Quit

Open in new window

LVL 4
internetsavantAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Krys_KConnect With a Mentor Commented:
Hi There
Unfortunately you cannot loop through "Primary Groups" to get their memberships list (As you already found out)
Every group in AD has a n attribute called PrimaryGroupToken which is given a number. The Builtin Groups, i.e. Domain Users, Domain Computers etc. have a universal number, menaing every AD will be the same number;, of 515 for Domain Computers, 513 for Domain Users etc.
Every Computer (and user) will have a primary group and their primary group attribute called PrimaryGroupID will have a number of (assuming their primary group is Domain Computers - becuase this can be changed) will have a number of 515.
So in order to list all computers in the Domain Computers group you need to search all computer objects with a PrimaryGroupID of 515.
A bit convoluted i know, but that is how its done it seems.
Hope that helps explain the situation for you. In my vbscript I would use ADO to search AD for all objects that has a PrimaryGroupID of 515 as the best way to do this.
Regards
Krystian
 
0
 
Krys_KCommented:
To help you get started and build an ADO script with what you need, have a look at this excellent site by Richard Mueller ADO Search Tips
Regards
Krystian
0
All Courses

From novice to tech pro — start learning today.