Hello all,
I am writing a script that queries AD for all computers that are part of our domain, along with some additional attributes of the computer's AD object, then connects to that computer and looks for something (not relevant here), and outputs the results into several log different log files based on results. At any rate, everything works just fine except for displaying the computer's description attribute from AD. Here's some sample code of the problematic bit:
When I run the script it is erroring out on the "Wscript.Echo strDescription" line with a type mismatch error. I can change it so that it displays the name, operatingSystem attributes, or most any other attribute. But it always hangs on the description. I have checked using ADSIEdit and the objects being returned do have descriptions attached, and the AD description attribute appears to be the field that has the data that I want (in AD Users and Computers we put make/model/serial number in the description field). If I change the last line to "Wscript.Echo objRecordSet.Fields("description")" I still get the type mismatch.
I suspect that for some reason the description attribute is returned in format other than the expected format, but I have no way to determine what it is returning. I keep seeing references to the Active Directory Programmer's Guide on MSDN, but all of the links to it that I have found appear to be dead. Is the description attribute returned as an array or something goofy like that?
Anyone have any ideas?
I am writing a script that queries AD for all computers that are part of our domain, along with some additional attributes of the computer's AD object, then connects to that computer and looks for something (not relevant here), and outputs the results into several log different log files based on results. At any rate, everything works just fine except for displaying the computer's description attribute from AD. Here's some sample code of the problematic bit:
Code:
' Connects to AD and executes query
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Sort On") = "CN"
objCommand.CommandText = "<LDAP://dc=mydomain,dc=com>;(objectCategory=computer);description,name,operatingSystem;subtree"
Set objRecordset = objCommand.Execute
Set objFile = objFSO.OpenTextFile(strLogFile, ForAppending)
WScript.Echo "Gathering data from Active Directory ..."
objFile.Writeline "Gathering data from Active Directory ..."
objFile.Close
objRecordSet.MoveFirst
intRecordCount = 0
intOnlineCount = 0
intOfflineCount = 0
intRXMInstall = 0
intUpgraded = 0
Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields("Name")
strDescription = objRecordSet.Fields("description")
If IsPingable(strComputer, "", "") Then
strPingResult = "Online"
intOnlineCount = intOnlineCount + 1
strLogData = strComputer & " " & strPingResult & " - " & Now
Set objFile = objFSO.OpenTextFile(strLogFile, ForAppending)
Wscript.Echo strLogData
objFile.WriteLine strLogData
objFile.Close
Wscript.Echo strComputer
Wscript.Echo strDescription
When I run the script it is erroring out on the "Wscript.Echo strDescription" line with a type mismatch error. I can change it so that it displays the name, operatingSystem attributes, or most any other attribute. But it always hangs on the description. I have checked using ADSIEdit and the objects being returned do have descriptions attached, and the AD description attribute appears to be the field that has the data that I want (in AD Users and Computers we put make/model/serial number in the description field). If I change the last line to "Wscript.Echo objRecordSet.Fields("description")" I still get the type mismatch.
I suspect that for some reason the description attribute is returned in format other than the expected format, but I have no way to determine what it is returning. I keep seeing references to the Active Directory Programmer's Guide on MSDN, but all of the links to it that I have found appear to be dead. Is the description attribute returned as an array or something goofy like that?
Anyone have any ideas?