Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstalling an application via uninstallString using powershell in WPF application

I am trying to uninstall software using below Powershell script in an WPF application

get-package |where name -like "Notepad++ (64-bit x64)" |% { & $_.Meta.Attributes["UninstallString"] /S}

the above command works only for Notepad++ (64-bit x64) but fails when I tried with software's like Git version 2.25.1 and TortoiseGit 2.10.0.0 (64 bit)

For Git version 2.25.1

get-package |where name -like "Git version 2.25.1" |% { & $_.Meta.Attributes["UninstallString"] /S} 

I am getting the below error:

& : The term '"C:\Program Files\Git\unins001.exe"' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:59 + ... "Git version 2.25.1" |% { & $_.Meta.Attributes["UninstallString"] /S} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: ("C:\Program Files\Git\unins001.exe":String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

For TortoiseGit 2.10.0.0 (64 bit)

 get-package |where name -like "TortoiseGit 2.10.0.0 (64 bit)" |% { & $_.Meta.Attributes["UninstallString"] /S} 

I am getting below error:

The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object. At line:1 char:70 + ... t 2.10.0.0 (64 bit)" |% { & $_.Meta.Attributes["UninstallString"] /S} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : BadExpression

I also tried using WMI objects powershell script below is the script

Get-WmiObject -Class Win32_Product | Where {$_.Name -like \"{returnStr}\"}  | foreach {$_.Uninstall()}".Replace("{returnStr}", Notepad++ (64-bit x64))   

Above script only works for the software's that were installed via an MSI

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

like image 839
Divyashri Rao Avatar asked Dec 18 '25 07:12

Divyashri Rao


1 Answers

You can find Uninstall-Package your friend here:

get-package | where-object name -like "Notepad++ (64-bit x64)" | ForEach {uninstall-package}
like image 154
programmer365 Avatar answered Dec 20 '25 21:12

programmer365



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!