Announcement

Collapse
No announcement yet.

How do I enumerate all computers and their description field?

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

  • How do I enumerate all computers and their description field?

    I have the following script which needs to list the computer name and description. It works until it loops to one particular computer, I suppose the first one it finds with a description set, and crashes.

    Here's the code:
    Code:
    ' On Error Resume Next
    
    Dim PCQuery, objConnection, objCommand, objRecordSet
    Dim oRootDSE, strDNC
    
    'First get domain information
    Set oRootDSE = GetObject("LDAP://rootDSE")
    strDNC = oRootDSE.get("defaultNamingContext")
    ' other categories = computer, user, printqueue, group
    PCQuery = "<LDAP://" & strDNC & _
         ">;(objectCategory=computer)" & _
           ";distinguishedName,name,description,location;subtree"
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Open "Provider=ADsDSOObject;"
    objCommand.ActiveConnection = objConnection
    objCommand.CommandText = PCQuery
    Set objRecordSet = objCommand.Execute
    
    Dim strComputer
    Dim strComputerDN 
    Dim strComputerDesc  
    ' Dim strComputerLocation  
    Dim Counter
    
    objRecordSet.movefirst
    Do Until objRecordSet.EOF
    	Counter = Counter + 1
        'assign the computer name and distinguished path to variables
        strComputer = objRecordSet.Fields("name")
        strComputerDN = objRecordSet.Fields("distinguishedName")
        strComputerDesc = objRecordSet.fields("Description")
        ' strComputerLocation = objRecordSet.fields("Location")
        'Put the worker process of your code in here
        '*******************************************
    
        If strComputerDesc <> ""  Then
        ' If strComputerDesc <> "" Or strComputerLocation <> "" Then
    	    WScript.Echo "*******************************************"
    	    wscript.Echo strComputer
    	    wscript.Echo strComputerDN 
    	    wscript.Echo strComputerDesc 
    	    ' wscript.Echo strComputerLocation
    	    WScript.Echo "*******************************************"
    	End If
     
        '******************************************* 
        strComputer=""
    	strComputerDN =""
    	strComputerDesc ="" 
    	' strComputerLocation=""
        objrecordset.MoveNext
    Loop
    
    objConnection.Close
    
    WScript.Echo "Script Finished"
    It crashes on the line:

    If strComputerDesc <> "" Then

    With the error:

    Exception: Type mismatch

    Looking at the variable strComputerDesc, I can see the following:

    ?strComputerDesc
    {...}
    (0): "VM MACHINE. DO NOT MOVE"
    So, it looks like it's an array of values. So how can I get the variable strComputerDesc to contain all values of the objRecordSet.fields("Description") property as one big string?
    |
    +-- JDMils
    |
    +-- Regional Systems Engineer, DotNet programmer & Jack of all trades
    |
Working...
X