KACE K1000 removes quotation marks which makes my CIR fail
Hi,
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
tor.
At line:1 char:69
+ Get-ChildItem -path cert:\CurrentUser\Root | where {$_.subject -like <<<< *XXXXXXXX*}
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
ception
+ FullyQualifiedErrorId : ExpectedValueExpression
[string]
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
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
SMal.tmcc
9 years ago
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*'}")
Comments:
-
That makes the CIR not turn up in the inventory of the devices I forced an update on. - IsakJ 9 years ago
-
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" - SMal.tmcc 9 years ago
Posted by:
jknox
9 years ago
Do you get that same error with no additional escaping or quotes? Is this running under the LocalSystem context?
Also, try it like this:
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.Comments:
-
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. - IsakJ 9 years ago
-
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. - jknox 9 years ago-
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) - IsakJ 9 years ago
Posted by:
flip1001
9 years ago