3

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!

2 Answers 2

2

You can find Uninstall-Package your friend here:

get-package | where-object name -like "Notepad++ (64-bit x64)" | ForEach {uninstall-package}
Sign up to request clarification or add additional context in comments.

5 Comments

Hi,I tried with the mentioned script but I am getting error -Uninstall-Package : Parameter set cannot be resolved using the specified named parameters. At line:1 char:75 + ... ect name -like "Notepad++ (64-bit x64)" | ForEach {uninstall-package} + ~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Uninstall-Package], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
Hi ,I tried with the command: get-package | where-object name -like "Notepad++ (64-bit x64)" | ForEach {Uninstall-Package -Name $_.Name } , I did not get any error however package is still not getting uninstalled.
Try removing the ForEach and just Uninstall-Package after pipeline.
Hi, tried with the command : get-package | where-object name -like "Notepad++ (64-bit x64)"| Uninstall-Package ,same issue no error and still package remains uninstalled. Also,I noticed the same command is working for TortoiseGit 2.10.0.0 (64 bit)
That only works with msi providers.
2

You have to get rid of the double quotes. Replacing " with $null or no 2nd arg. Uninstall-package doesn't work for non msi installs. Also this only works in windows powershell 5.1, not powershell 7 currently. Does TortoiseGit have an uninstallstring?

get-package "*Git version 2.25.1*" | 
  % { & ($_.Meta.Attributes["UninstallString"] -replace '"') /S} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.