KACE Product Support Question

Issue running WMIC with the LIKE operator in a custom inventory rule?

01/19/2013 10380 views

Attempting to use a custom inventory rule to return mappings to network printers (printers that print to an IP port).  WMIC command as-written works on XP and returns the expected results:

WMIC PRINTER WHERE "PortName LIKE 'IP_%'" GET Name,DriverName,PortName /format:value


The custom inventory rule in KACE appears as:

ShellCommandTextReturn(WMIC PRINTER WHERE "PortName LIKE 'IP_%'" GET Name,DriverName,PortName /format:value)


However, the rule fails because KACE is dropping the quotations (") in the arguments list according to kdeploy.log.  This results in a syntax error for WMIC (invalid alias verb).

[Sat Jan 19 13:16:48 2013] KLaunch    Execute command=[WMIC] args=[PRINTER WHERE PortName LIKE 'IP_%' GET Name,DriverName,PortName /format:value]
[Sat Jan 19 13:16:48 2013] LIKE
[Sat Jan 19 13:16:48 2013]  - Invalid alias verb.

Has anyone seen this before?  I thought about passing an invalid expression (e.g., double quotes) hoping at least one set of quotes would be preserved.

Answer Summary:
0 Comments   [ + ] Show comments


All Answers


What if you type \" instead of ", (escape the quotes.)?

ex., ShellCommandTextReturn(WMIC PRINTER WHERE \"PortName LIKE 'IP_%'\" GET Name,DriverName,PortName /format:value)

Answered 01/19/2013 by: flip1001
Black Belt

  • Worked:
    [Date/time] KLaunch Command="WMIC" Args="PRINTER WHERE "PortName LIKE 'IP_%'" GET Name,DriverName,PortName /format:value" </snip>
  • Well, not so fast. WMIC is actually running but returning "No instances available" to KACE. I can run the exact same code (sans escaping the quotes) from the same PCs command line and it's returning the expected result (a mapped printer with portnmae like IP_. Have debug enabled and WMIC seems happy with the syntax. Unsure where to go from here. Still hacking at it.
  • I also just realized you might have to run the script under the user's account since the default is to run the command under the SYSTEM account. But the user may not be able to run WMIC with restricted permissions.

    Here are 2 more articles that might help.



Using WMI Code Creator (http://www.microsoft.com/en-us/download/details.aspx?id=8572), I generated this code. I modified it slightly to look for IP printers. But since I don't have an IP printer at home I can't test it yet.

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT Name, DriverName, PortName FROM Win32_Printer WHERE PortName Like 'IP_%'",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_Printer instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "DriverName: " & objItem.DriverName
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PortName: " & objItem.PortName
Answered 01/19/2013 by: flip1001
Black Belt

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ