long time user, first time poster I’m currently working on an uninstall app for Sophos Endpiont Defense and I’m stuck at a particular point. As there can be many features in any given Sophos installation, I need to find all installed products and their MSI product code AND their uninstall string, if there is one. That’s not a problem, I use the following code to do that (in a for/each loop where $Product is the DisplayName of the Sophos product, which is known):
$Reg64MSIProductCode = Get-ItemProperty "$UninstallRegPath64\*" | Where-Object -Property DisplayName -Like "$Product" | Select-Object PSChildName,UninstallString,QuietUninstallString
The problem I’m facing, that I can’t seem to solve, is the following: PSChildName is the MSI product code which works fine, if the product can be uninstalled via MSI. However, if I use the UninstallString or QuietUninstallString, the App Deployment Toolkit fails with an error in the function “Execute-Process”. This seems to be due o the fact, that both strings have quotation marks in them and these are of course retrieved when retrieving the string, i.e. “C:\Program Files\Notepad++\uninstall.exe” /S (I’ll use Notepad++ as an example here) for the QuietUninstallString. I go ahead and split the string at / in order to seperate the path and parameters. So far so good. My line is then
Execute-Process -Path $UninstallString -Parameters "/$Parameters" -WindowStyle 'Hidden' -Wait -ErrorAction Stop
Then I’ve tried using trim(‘"’,’ '), split, etc. on $UninstallString in order to get rid of the quotation marks and the ending space that occurs after the initial split. When I do this manually in the console, it works. If I do it in the script, it doesn’t. If I define the path as a variable and enter the path manually, i.e. $UninstallString = “C:\Program Files\Notepad++\uninstall.exe”, the function works fine and the product in uninstalled without problems. My line is then:
Execute-Process -Path "$UninstallString" -Parameters "/$Parameters" -WindowStyle 'Hidden' -Wait -ErrorAction Stop
If I use the same line (with “” around $UninstallString) without manually defining the variable, the function fails aswell (just wanted to clarify in case someone points out the “” are missing in the first Execute-Process line).
So I guess my question is - does anybody know how to properly format the result I get from the registry in order for Execute-Process to properly work?