0

I've been tasked to uninstall "Rhino 6" from all Windows 10 computers. If I run:

gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Rhino 6" } | select UninstallString

Then I get a very useful:

UninstallString
---------------
"C:\ProgramData\Package Cache\{680b3429-6aab-4318-a4e1-74347755c79d}\Bootstrapper.exe"  /uninstall

So, I wrote this:

Start-Process "C:\ProgramData\Package Cache\{75519ff1-80d4-4471-96c0-970328e182f1}\Bootstrapper.exe" -ArgumentList "/uninstall -quiet"

Which works great, except that there are MANY versions of "Rhino 6" and they each spit out a different uninstall string.

How can I make a script that does the first command and then uses the path from the answer in the second command without all of the other stuff that gets spit out?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Ashkaan
  • 3
  • 2
  • 6
    If you're looking for a general way to invoke a command line stored in an `UninstallString` registry value, see [this answer](https://stackoverflow.com/a/68382753/45375). – mklement0 Jan 30 '22 at 00:36
  • 2
    Does this answer your question? [How to uninstall MSIs using the Uninstall Path](https://stackoverflow.com/questions/68382074/how-to-uninstall-msis-using-the-uninstall-path) – zett42 Jan 30 '22 at 02:14
  • I don't see the answer to my question in that post. I'm asking how to strip away the "UninstallString ---------------" portion of the output so that I can use it as a variable. – Ashkaan Jan 31 '22 at 01:21

1 Answers1

0

Something like this should work. Assign the output of your get child item (gci) then foreach loop to access the value that is assigned to $rhino.UninstallString

#HashTable
$rhino = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Rhino 6" } | Select UninstallString
#Output of $rhino: @{UninstallString=C:\somepath\some.exe}@{UninstallString=C:\someotherpath\some.exe}

#Loop through assigning each to $uninstall and use $uninstall.UninstallString to start-process
foreach ($uninstall in $rhino) {
    Start-Process $uninstall.UninstallString -ArgumentList "/uninstall -quiet"
}
sr02
  • 11
  • 2
  • Hi this doesn't work because the output from $rhino has a bunch of additional text, namely: UninstallString --------------- – Ashkaan Jan 31 '22 at 01:21
  • The uninstallstring ---- won't be assigned to the $rhino var. You can validate this by doing 'write-host $rhino' – sr02 Jan 31 '22 at 01:40
  • See this [example](https://imgur.com/a/ipHEew5) Note this is missing from the outputs `UninstallString -----------------` – sr02 Jan 31 '22 at 01:54
  • 1
    The gci command you run above without assigning it to a variable `$rhino` will simply output the table. More information on the default output of cmdlets can be found [here](https://learn.microsoft.com/en-us/powershell/scripting/samples/using-format-commands-to-change-output-view?view=powershell-7.2) – sr02 Jan 31 '22 at 01:57
  • Weird that it didn't work in testing. I'll have to play with this. Thank you. – Ashkaan Feb 01 '22 at 04:09