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!