/build/static/layout/Breadcrumb_cap_w.png

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

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.


0 Comments   [ + ] Show comments

Answers (2)

Answer Summary:
Posted by: flip1001 11 years ago
Black Belt
1

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

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


Comments:
  • Worked:
    [Date/time] KLaunch Command="WMIC" Args="PRINTER WHERE "PortName LIKE 'IP_%'" GET Name,DriverName,PortName /format:value" </snip> - blaise_gregory 11 years ago
  • 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. - blaise_gregory 11 years ago
  • 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 - flip1001 11 years ago
Posted by: flip1001 11 years ago
Black Belt
1

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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
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