Question

I've got a few question that have remained unanswered as I make my way through a Powershell project I'm working on.

My goal, to create a Powershell script that is able to uninstall a ClickOnce deployed C# application, in addition to potentially running various installers(but this part I'll worry about later).

I've been able to figure out how to get the UninstallString for my application, I'm just stuck on what my options are with it. I've tried running it using Invoke-Expression and a few other methods, but nothing yielded results. Since I'm brand new to Powershell chances are good I may have done something wrong, but I'm hoping I just haven't found the right way of doing this. Here is my current snippet of relevant code that I'm using to get my UninstallString:

$App = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" | 
    foreach { gp $_.PSPath } | 
    select DisplayName,DisplayVersion,InstallDate,Publisher,UninstallString | 
    where { $_.DisplayName -match "scan" }

If anyone has suggestions on how to proceed it would be much appreciated!

Was it helpful?

Solution

Oh good lord this brings back memories of a VBS script I cobbled together years ago that would bring up an HTML interface that would let you enter a computer name, and if it was on the network it would scan the remote registry for things in the Uninstall key, strip out KB's, and give you a dropdown list of things to uninstall. Hundreds if not thousands of lines of script that I'll never use again. Anyway, enough reminiscing.

You should be able to use the Call operator "&" to run the string in the UninstallString property like such:

& $App.UninstallString

Now, having said that you'll want to take something into consideration. If it is something executed with MSIEXEC.EXE there's a really good chance that they have it set to MSIEXEC.EXE /I {<some GUID>} and you will probably want to replace the /I with /X and append /NB-! to the end of the string (if I remember my switch right that will give a minimal progress bar display and suppress any "Uninstall Complete" windows that may pop up).

OTHER TIPS

I skimmed this - too tired to read all of it :-), and I just want to add a link to an article with an uninstall string for PowerShell in the hopes it sends you in the right direction: Uninstalling an MSI file from the command line without using msiexec

Here's an example I just had to work out. The & or call operator needs a cmd string and then an argument string array. Powershell 5.1 only to work with programs or msi providers.

$uninstall = -split (get-package 'Support Button *bomgar*' | 
  % { $_.metadata['uninstallstring'] })
& $uninstall[0] $uninstall[1..($uninstall.length-2)]  # take off last arg --prompt

Or if you want to wait, it's the same idea:

start -wait $uninstall[0] $uninstall[1..($uninstall.length-2)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top