Enumerate objects within Domain Computers?

Posted on 2009-05-01
Last Modified: 2012-05-06
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)


arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members of Group " & strContainer

For Each strMember in arrMemberOf

   WScript.echo strMember



Open in new window

Question by:internetsavant
    LVL 12

    Accepted Solution

    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.
    LVL 12

    Expert Comment

    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

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This is an addendum to the following article: Acitve Directory based Outlook Signature ( The script is fine, and works in normal client-server domains…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now