Announcement

Collapse
No announcement yet.

List all computers in a domain

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • List all computers in a domain

    I have the following script which I can't get working:
    const FileName ="domaincomputers.csv"
    set cmd = createobject("ADODB.Command")
    set cn = createobject("ADODB.Connection")
    set rs = createobject("ADODB.Recordset")

    cn.open "Provider=ADsDSOObject;"
    cmd.activeconnection = cn

    set objRoot = getobject("LDAP://v.com.au/cn=Computers,dc=voyager,dc=com,dc=au") ' RootDSE

    cmd.commandtext = "<LDAP://" & objRoot.get("defaultNamingContext") & ">;(objectCategory=Computer);" & _
    "name,operatingsystem,operatingsystemservicepa ck, operatingsystemversion;subtree"
    '**** Bypass 1000 record limitation ****
    cmd.properties("page size")=1

    set rs = cmd.execute
    set objFSO = createobject("Scripting.FileSystemObject")
    set objCSV = objFSO.createtextfile(FileName)

    q = """"

    while rs.eof <> true and rs.bof <> true
    objcsv.writeline(q & rs("name") & q & "," & q & rs("operatingsystem") & q & _
    "," & q & rs("operatingsystemservicepack") & _
    q & "," & q & rs("operatingsystemversion") & q)
    rs.movenext
    wend

    objCSV.Close
    cn.close

    wscript.echo "Finished"
    I get an error on line:
    set objRoot = Getobject("LDAP://v.com.au/cn=Computers,dc=voyager,dc=com,dc=au")

    The error is:
    Line 11
    Char 1
    The directory property cannot be found in the cache.
    Code 8000500D
    Source Active Directory

    As a test, my computer's distinguished name is (from a working script):

    CN=JULIAN,CN=COMPUTERS,DC=V,DC=COM,DC=AU

    I'm running this script from my WinXP workstation. Thanks.

    PS. My next step is for the script to ask for the domain to query via an input box.
    |
    +-- JDMils
    |
    +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
    |

  • #2
    Re: List all computers in a domain

    <<BUMP>>
    |
    +-- JDMils
    |
    +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
    |

    Comment


    • #3
      Re: List all computers in a domain

      Guess where I found this? Note also the search string, gee, that looks like the title of your thread.

      http://www.google.com.au/search?sour...rs+in+a+domain

      JD, try adding the search engine to YOUR Favorites!!
      1 1 was a racehorse.
      2 2 was 1 2.
      1 1 1 1 race 1 day,
      2 2 1 1 2

      Comment


      • #4
        Re: List all computers in a domain

        You use 'Set objRoot' to bind to a OU, but the script needs the rootDSE for naming information. That line must be:
        Code:
        Set objRoot = GetObject("LDAP://rootDSE")
        If you make that change in your script it will run fine (well... except for the typo later on in the script => 'operatingsystemservicepa ck' should not contain a space!).


        But I guess that you do not want to query the whole Active Directory, just the container 'Computers'. In that case you can adjust the LDAP query:
        Code:
        const FileName ="domaincomputers.csv"
        set cmd = createobject("ADODB.Command")
        set cn = createobject("ADODB.Connection")
        set rs = createobject("ADODB.Recordset")
        
        cn.open "Provider=ADsDSOObject;"
        cmd.activeconnection = cn
        
        cmd.commandtext = "<LDAP://" & _
         "cn=Computers,dc=voyager,dc=com,dc=au>; " & _
           "(objectCategory=Computer);" & _
           "name,operatingsystem," & _
           "operatingsystemservicepack,operatingsystemversion;" & _
           "subtree"
        		  
        '**** Bypass 1000 record limitation ****
        cmd.properties("page size")=1
        
        set rs = cmd.execute
        set objFSO = createobject("Scripting.FileSystemObject")
        set objCSV = objFSO.createtextfile(FileName)
        
        q = """"
        
        while rs.eof <> true and rs.bof <> true
        	objcsv.writeline(q & rs("name") & q & "," &  q & _
        	rs("operatingsystem") & q & "," & q & _ 
        	rs("operatingsystemservicepack") & q & "," & q & _
        	rs("operatingsystemversion") & q)
        	rs.movenext
        wend
        
        objCSV.Close
        cn.close
        
        wscript.echo "Finished"

        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: List all computers in a domain

          JD, try adding the search engine to YOUR Favorites!!
          LA LA LA LA.....yeah, you really need to go to Googles Anonymous for that Google thing you got, Chris I'm trying to fix my script not recreate the wheel.

          Top marks REM.
          |
          +-- JDMils
          |
          +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
          |

          Comment


          • #6
            Re: List all computers in a domain

            Sorry JD, I just couldn't resist. Hope you assigned Rems (VB, and not the green tinny kind, scripting guru) the appropriate thanks with some Reputation Points. (more subtle humour)

            Rems, you ARE the Man. I read your work (ok, I try to read your work) with awe and envy!!!

            -------------------------------------------------

            Hi, my name is Chris and I am addict.

            "HI Chris"
            1 1 was a racehorse.
            2 2 was 1 2.
            1 1 1 1 race 1 day,
            2 2 1 1 2

            Comment

            Working...
            X