5.5 Agent Custom Inventory Rule -Powershell
Does anyone know the proper syntax for Powershell custom inventory rules in 5.5? I haven't had a ton of time to investigate it. I've added the cmd.exe /c to the majority of my "ShellCommandTextReturn" rules and that has resolved them. Just trying to get this resolved before I upgrade here in a couple of months.
This worked in 5.4, but no longer with the 5.5 agent.
ShellCommandTextReturn(powershell Get-WmiObject Win32_ComputerSystemProduct | Select Version)
I've tried this with 5.5, but it returned no results. I'm not seeing errors in the logs, just that it did not return anything.
ShellCommandTextReturn(cmd.exe /c powershell Get-WmiObject Win32_ComputerSystemProduct | Select Version)
Answers (1)
ShellCommandTextReturn(cmd /c powershell "Get-WmiObject Win32_ComputerSystemProduct | Select Version")
ShellCommandTextReturn(cmd /c "powershell \"Get-WmiObject Win32_ComputerSystemProduct | Select Version\"")
should work. you need to encapsulate it in " because else from Win32 will be interpreted as add. command for cmd
If you have multiple " use \" for escaping them
Comments:
-
Thanks Nico. That got me on the right track. I used the rule below and it worked for both the 5.4 and 5.5 agent.
ShellCommandTextReturn(cmd /c powershell "Get-WmiObject Win32_ComputerSystemProduct | Select Version") - dugullett 11 years ago-
great to hear, but in my 5.5GA it only works if I also encapsulate the powershell in ", _THIS_ is strange - Nico_K 11 years ago
-
I thought that would work also? I tested it with a CMD prompt to make sure. I would think that it would not return any results with the command in " ". Since entering it this way in Powershell returns nothing. I'm wondering if it's a Windows thing, and not a Kace thing?
C:\Windows\system32>cmd /c "powershell get-wmiobject win32_ComputerSystemProduct
|Select Version"
'Select' is not recognized as an internal or external command,
operable program or batch file.
C:\Windows\system32>cmd /c powershell "get-wmiobject win32_ComputerSystemProduct
|Select Version"
Version
-------
ThinkCentre M91p - dugullett 11 years ago
-
strange, well currently I prefer to end my shift (after 12hr ... again ... ) and don't think about until tomorrow ;) - Nico_K 11 years ago