/build/static/layout/Breadcrumb_cap_w.png

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.



0 Comments   [ + ] Show comments

Answers (2)

Posted by: Nico_K 4 years ago
Red Belt
1

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.

Posted by: b-rye 4 years ago
White Belt
0

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." )






 
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