I have the following JavaScript to execute a WMI query on a remote Windows host:
var wmiLocator = WScript.CreateObject("WbemScripting.Swbemlocator");
var wmiService = wmiLocator.ConnectServer(host, "root\\cimv2", user, pass);
var items = wmiService.ExecQuery(query);
for(var e = new Enumerator(items); ! e.atEnd(); e.moveNext())
{
WScript.StdOut.Write(e.item().GetObjectText_());
}
user
and pass
are the login credentials for the remote host
, query
is the WQL query to be performed.
This all works fine until I add a WHERE clause to the WQL query. For instance,
SELECT * FROM Win32_LogicalDisk
yields the expected result, but
SELECT * FROM Win32_LogicalDisk WHERE DriveType=3
will result in an "Invalid Parameter" error (wbemErrInvalidParameter / 0x80041008).
I've found numerous examples in which WHERE clauses are used, and I cannot find any info about it not being supported. Am I missing something here?
In case it is any relevant, the host executing this script is a Windows XP Professional with SP2.
As hinted by Helen, I am answering this myself.
The query string was changed by some parsing I did earlier in my script and became syntactically invalid, hence the invalid parameter error.