Custom Inventory Rule by running uploaded .ps1
Hello,
Is there any way to create a Custom Inventory Rule by running the specific uploaded file on it.
For example, I will create a test.ps1 to return an specific value and I want to store it on the Custom Inventory Rule.
ShellCommandTextReturn"cmd /s /c powershell -file "$VARIABLE\test.ps1"
Is there any way to do that?
Thanks for the Help.
Answers (2)
It is not possible to get the results directly into the CIR, since a CIR works differently.
Do the Following:
1. Upload the Powershell Script to the Software Item you created for it
2. Setup the CIR in the very same Software Item
3. Use a File Sync to get the Powershell Script into the systems: Distribution|File Syncronization
4. run a
c:\program files (x86)\quest\kace\runkbot 6 0
followed by a
c:\program files (x86)\quest\kace\KDeploy -custominventory
this will trigger the File Sync and only runs the CIR without a full Inventory (which is much faster) and you see the results directy.
Hi,
I do not believe there is any reason to do that.
Why not just use a scriptblock ?
While you could use the kace 'files' section to just push the ps1 and execute it via its explicit path in your inventory rule, have a look at what I am currently using to list local admins :
ShellCommandTextReturn(c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass "invoke-command -ScriptBlock {Get-LocalGroupMember -Group "Administrators" | Format-Table -HideTableHeaders -Property ObjectClass,Name} -ErrorAction SilentlyContinue" 2> nul) or ShellCommandTextReturn(net localgroup administrators | findstr /l /v "Alias name Comment Members ------------------------------------------------------------------------------- command completed successfully." )
To space that out ...
#standard "ShellCommandTextReturn"
ShellCommandTextReturn(c:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe
#don't waste time with profiles
-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass
"invoke-command -ScriptBlock {Get-LocalGroupMember -Group "Administrators" | Format-Table -HideTableHeaders -Property ObjectClass,Name} -ErrorAction SilentlyContinue" 2> nul)
# if the powershell errors out, execute the old-and-busted dos query :
or ShellCommandTextReturn(net localgroup administrators
#remove the annoying string that net.exe inserts
| findstr /l /v "Alias name Comment Members ------------------------------------------------------------------------------- command completed successfully." )