[Q] WMI 'where ... like' statement

From: Johnny Slos (Slos_at_discussions.microsoft.com)
Date: 10/25/04


Date: Mon, 25 Oct 2004 05:11:02 -0700

Hi,

I wanted to get a list of all machines running a windows OS. I altered a
script from the scripting library :

==================================

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, Location from 'LDAP://DC=SD,DC=DIKA,DC=BE' " _
        & "Where (objectClass='computer') and (operatingSystem like
'Server') "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

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

========================

But whenever i run it using : cscript servernames2.vbs

I get the followin error : servernames2.vbs(14, 1) Provider: One or more
errors occurred during processing of command.

If I cut the like part out of the script all works fine. So it has to do
with the like part of the where clause. Any Ideas what's wrong ?

Johnny


Loading