how to list all AD computer descriptions with a vbscript

Associate
Joined
8 Mar 2007
Posts
2,176
Location
between here and there
hey guys,

I'm trying to find a script that will list all the computer names and descriptions in AD via a vbscript.

So far I can list the names and locations but I'm struggling to get the description!

I'm creating a command prompt script that will open a admin command prompt on a remote PC via putty. So far my script works but you have to know either the ip address or the pc name. I'd like to be able to input a username and have the script search AD for a computer account with the name in the description and then give me the pc name.

Any ideas???

Cheers in advance
 
Thanks.

I've already been though evey site on that list!!

This is the code i have so far...

Code:
Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Description from 'LDAP://DC=our_domain,DC=com' " _
        & "Where objectClass='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    msgbox "Computer Name: " & objRecordSet.Fields("Name").Value & " : " & objRecordSet.Fields("Description").Value
    objRecordSet.MoveNext
Loop

It errors on line 18 which is the msgbox displaying the results. If I comemnt out the section asking it to display the field 'description' it works fine otherwise I get an type mismatch error - the data is invaild.

????

It almost as if the record set has no field called description in it. I tried changing the fields that it pulls by editing line 9 with 'select *'... but that hasn't made any difference

Thanks again :)
 
Last edited:
Do you need () after objRecordSet.Fields("Name").Value before you join your next bit of text for your message box - seem to remember having the same sort of problem myself before...
 
Do you need () after objRecordSet.Fields("Name").Value before you join your next bit of text for your message box - seem to remember having the same sort of problem myself before...

if only......

I've now put both coumpter name and description on a line each in thier own msgbox. Sadly that hasn't fixed it either. :(
 
I've just added this line

Code:
For Each objField In objRecordset.Fields
   MsgBox objfield.Name
Next

and it's telling me that the 2 fields that I've pulled from AD are called Name and Description, but if I try to view the value of the description filed I'm getting an 'invaild data' error.

I was under the impression that the description value was just a sting and could be sent to a msgbox without an problems.

Am I wrong??
 
thanks :)

error: either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record.

system: power has been restored at %1. The server is no longer paused


:(
 
So it turns out that some of the computers in AD have no description and therefore some are showing up now as isnull.

This still leaves me with the issue for getting the value out of the descriptions that do have text in them.

any more ideas??

Thanks for all your effort so far :)
 
If you're going to be searching using particular username or multple ones then put it in a function and have it return the description,


If isNull(objRecord.Fields("Description").Value) Then
' Description is of no use to us do whatever you need

Else
' Do whatever you need to do e.g. check for username passed
strReturnVal = objRecord.Fields("Description").Value

End If

yourFunction = strReturnVal


Else
 
Back
Top Bottom