Powershell script in Custom INventory Rule
Dear All,
I've developed a powershell script to get the value of an UninstallString in the registry. That script matches the DisplayName with a parameter and if that does the value in the UninstallString will return. I've added in the Custom Inventory Rule of a customized Managed Installation the function ShellCommandTextReturn with the powershell script. When the script is launched on a WIndows 8.1 x64 system, no information are displayed in the Custom Inventory Fields of that system.
That's the complete function syntax:
ShellCommandTextReturn(powershell.exe -NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& {(Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\uninstall\ -Recurse) | foreach-object {gp $_.pspath} | where {$_.DisplayName -like "*java*"} | select -ExpandProperty UninstallString}).
Adding Backslashes before special characters and single or double quotes in the powershell command doesn't return the expected value. The CI field displays a powershell error message.
What do i wrong? Could someone help me with this problem?
Kinds regards,
Patrice Renard
Answers (5)
ShellCommandTextReturn(cmd.exe /c if defined ProgramFiles(x86) (C:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\uninstall\ -Recurse | foreach-object {gp $_.pspath} | where {$_.DisplayName -like '*java*'} | select -ExpandProperty UninstallString") else (powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\uninstall\ -Recurse | foreach-object {gp $_.pspath} | where {$_.DisplayName -like '*java*'} | select -ExpandProperty UninstallString") 2>nul)
Why are you reinventing the wheel? You create unecessary overhead on your workstations by having to run this task every inventory cycle as a CIR. If you want to run this yourself run it as a script. You do not need a CIR or script to get this info, you can just create a simple wizard report to find this.
wmic product where "name like 'Java 7%%' or name like 'Java 8%%'" get uninstall > java.txt
And if you just want to get all versions of java off the machine prior to pushing a new version use a call like:wmic product where "name like 'Java 7%%' or name like 'Java 8%%'" call uninstall
Comments:
-
3 years later, but I wanted to thank you for this. It was helpful. Was trying to generate a list of attached webcams and the only way that has been succesful was using powershell. And the variant that was working for me locally wasn't working for ShellCommandTextReturn and I think it was related to this 32 vs 64 bit issue you talked about. - five. 6 years ago
cmd /q /c powershell.exe -Command "(Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\uninstall\ -Recurse) | foreach-object {gp $_.pspath} | where {$_.DisplayName -match 'java'} | select -ExpandProperty UninstallString"