I'm looking to get a KACE K1000 report on the amount of computers that have a certain certificate. I've written a small PS script that suits my needs and runs perfectly fine on a computer:

Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like "*XXXXXXX*"}

To get the report, I made a Custom Inventory Rule that would run the script and return the text:

ShellCommandTextReturn(cmd /c "powershell.exe -command \"Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like \"*XXXXXXX*\"}\"")

However, although I've escaped what I've figured need to be escaped, I still get this error:

You must provide a value expression on the right-hand side of the '-like' opera
At line:1 char:69
+ Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like <<<< *XXXXXXXX*}
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx 
+ FullyQualifiedErrorId : ExpectedValueExpression


As you can see it's not reading the subject as a string. Somewhere in the process my quotation marks get removed. I don't know where to approach this from. Can I rework the way I type my script into K1000 or should I upload it as a file instead and launch it from the CIR field? I'm stuck.

Thanks in advance

(Obviously the XXXXXX is actually a certain certificate subject)

EDIT: I solved this by making a script that would write to a file. A CIR would later read the file, and thus, a correct report could be made.

0 Comments   [ - ] Hide Comments


Please log in to comment

Community Chosen Answer


try it like this, with a combination of single and double quotes.

ShellCommandTextReturn(cmd /c powershell.exe -command "Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like '*XXXXXXX*'}")
Answered 05/27/2015 by: SMal.tmcc
Red Belt

  • That makes the CIR not turn up in the inventory of the devices I forced an update on.
    • The more I look at this I think your solution of writing a file is the right way to go. CIR's run as system so when that runs it does not know how to handle the path of "currentuser"
Please log in to comment
Answer this question or Comment on this question for clarity


Do you get that same error with no additional escaping or quotes?  Is this running under the LocalSystem context?

Also, try it like this:

ShellCommandTextReturn(cmd /c "powershell.exe -command Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like "*XXXXXXX*"}")
If you can't figure it out, enable debug, force an inventory update.  Then get a KaptureState and submit a support ticket so that KACE can take a look.
Answered 05/26/2015 by: jknox
Red Belt

  • That's the first thing I tried. When it failed I went searching IT Ninja for a solution and based on previous answers I thought escaping might do the trick.
    • From a command prompt on a machine this should work on, run this assuming 64 bit:

      "C:\Program Files (x86)\Dell\KACE\kdeploy.exe" -custominventory

      That command may show you what the CIR is returning when it runs.
      • The error I listed in my original post is what the CIR is returning. I can replicate the same error in PS by running Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like *XXXXXXX*}

        (That's without the quotation marks)
Please log in to comment
ShellCommandTextReturn(cmd /c powershell.exe -Command "Get-ChildItem -path cert:\CurrentUser\Root | where-object {$_.subject -like '*XXXXXXX*'}")
Answered 05/27/2015 by: flip1001
Third Degree Brown Belt

Please log in to comment
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja