Script for uninstalling programs from Appwiz.cpl

Hey everyone!
Glad to see there is a community for PowerShell to help everyone!
I had some problems with a script I’ve made with PS.
I’ve wrote a script that uninstall programs from your Appwiz.cpl but unfortunately it doesn’t work.
At the start of the script I’ve asked the computer to show me all of my installed programs, and than to uninstall a programs according to name I give the script.
The thing is that the script show me that the program is uninstalled even after it shows the program on the script that shows me the installed programs!

the script:

Get the list of installed programs

$installedPrograms = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* | Select-Object DisplayName

Print the list of installed programs

Write-Output “Installed programs:”
Write-Output $installedPrograms

Uninstall a program

$programName = “7-Zip 19.00 (x64 edition)”

Get the list of installed programs

$installedPrograms = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* | Select-Object DisplayName

Check if the program is installed

$programExists = $installedPrograms -contains $programName
if ($programExists) {

Get the uninstall string for the program

$uninstallString = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall* | Where-Object {$_.DisplayName -eq $programName}).UninstallString

Uninstall the program

Start-Process cmd -ArgumentList “/c $uninstallString /quiet” -Wait
Write-Output “Successfully uninstalled $programName”
} else {
Write-Output “$programName is not installed”

And the out come is this (ive deleted the rest of my uninstalled programs from here)

Installed programs:


Notepad++ (64-bit x64)
7-Zip 19.00 (x64 edition)
Google Chrome

7-Zip 19.00 (x64 edition) is not installed

Thank you for your help!!

Welcome to the forum. :wave:t4:d

Before we proceed …

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

I’m not sure if I got what you mean.

Anyway … some comments:

With this command line you only catch 64 bit applications. You are aware of that, aren’t you? :wink:
I wouldn’t limit the output to DisplayName though. You could do this later on if needed.

Why again? You did not change anything. So it will be the same. So that command line is superfluous.

If you hadn’t limitted the output of the first command you’d already have all the needed properties already.
And … !!! Attention - not all uninstall strings uninstall their according program. Some of them just run the according setup executable. !!!

Now you’re starting a new command line interface from inside the command line interface. Why?
And … !!! Attention - not all setup executables will process the command line argument /quiet. !!!

That’s the part I don’t get. If you did uninstall an application you will have to re-run the query for the installed applications to get an updated list.

Regardless of all that - what you asked for is a very common and easy task. It has been asked for thousand times and it has been answered thousand times already. Use your prefered internet search engine to search for examples you can adapt to your particular needs. You don’t need the re-invent the wheel again. :wink:

Hi olaf!
Thank you for the quick response, I will look for scripts for that in the our forum and learn from them and from your comments!
Im a NewB in poweshell so im trying to learn the language…