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

0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

3
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.







Answered 03/25/2015 by: SMal.tmcc
Red Belt

Please log in to comment

Answers

0
Heya, remember powershell will run in 64bit mode on a..err 64bit system (:

You can either put some smarts into the script to work with 32 and 64 bit systems. Or you can explicitly launch the 32bit powershell process in the SYSWOW64 folder.

Or you could look in the registry WOW6432Node path.
Answered 03/25/2015 by: rileyz
Red Belt

Please log in to comment
0
Try this CIR. I also changed -like to -match because I never get double quotes to work inside the main command.

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"
Answered 03/25/2015 by: flip1001
Fourth Degree Green Belt

Please log in to comment
0
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


Answered 03/25/2015 by: SMal.tmcc
Red Belt

Please log in to comment
0
This is why I hate the lack of a 64 bit client and has given me some major headaches. The following can be used to pull the proper values back for both 64 bit and 32 bit systems. It is rather ridiculous that you have to go to these extremes to have a single inventory shell return item return properly for 32 and 64.

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)

I know SMal.tmcc stated,

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.
While for this specific example, there may be better ways, I find the question to still be valid. I find that answer leaves many without an answer to their similar question that may require a custom inventory object. The question Prenard was asking is relevant for a large number of similar issues. I have found that using shelltextreturns to pull data for both 64 bit and 32 bit machines to be completely broken. There are just too many cmd, powershell or other tools and utilities that just do not work properly on a 64 bit machine when called from a 32 bit process.

SMal.tmcc also pointed this out,

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

The get uninstall example won't actually return any uninstall strings since they aren't in the property list. However, in this example, wmic works on both 32 and 64 which is a good example of using an alternative method to solve a 32/64 bit issue. Careful when doing this before installing a new version of the software being uninstalled. I have found that when uninstalling in bulk via wmic, it triggers the need for a reboot. So if you are trying to script the uninstall of all old versions and the install of new version, you may encounter an error when trying to install the newer software. Java is actually the software I have had the most issues with in regards to that issue.

I wanted to share my solution to this particular problem since the wmic and reporting solutions that SMal.tmcc provided do not work in all of my own scenarios. I have used those solutions for some of my problems, but they are not viable in all. 

A quick example would be creating a Custom Inventory Item that is a registry entry that can be in multiple places and use multiple folder structures. I can create a single rule that searches for said Reg value in both 32 and 64 bit contexts and then returns the value as the object. I like to send any errors to nul so I do not get false positives. If you want, you can create a second rule without the nul if you want to weed out any potential errors and just monitor that Custom Inventory object for errors or bad return values. 

I use this to monitor for certain improperly set configurations and then trigger a managed install to correct the bad values. This just isn't viable trying to use the built in reporting, scripting or managed installations. 

I hope this helps, as it took me a while to troubleshoot this sort of custom inventory object.
Answered 06/25/2015 by: gerane
Senior White Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share