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:
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

0

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
Fourth Degree Green 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.

    http://www.itninja.com/blog/view/inventorying-reporting-on-user-profile-specific-other-non-inventoried-data

    http://www.itninja.com/blog/view/k1000-reports-default-all-local-printers-w-vbscripts
Please log in to comment
0

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
Next
Answered 01/19/2013 by: flip1001
Fourth Degree Green Belt

Please log in to comment
Answer this question or Comment on this question for clarity

Share