uninstalling an application via uninstallString

Hi guys, I am trying to uninstall an application on a remote server using uninstallstring, a property of Get-ItemProperty cmdlet in PowerShell, but failing to do so. I have also tried suggestions explained in another thread, click here to access the thread, however, my following script still do not uninstall the program, so please have a look.

$computer = SERVER NAME
invoke-command -computer $computer {
$paths='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
$app = Get-ChildItem -Path $paths | Get-ItemProperty | Where-Object {$_.DisplayName -like "*notepad*" }

# $app.uninstallstring returns "C:\Program Files\Notepad++\uninstall.exe"
Start-Process -FilePath cmd.exe -ArgumentList '/c', $app.uninstallstring  -Wait
}

I really appreciate your help.
Faraz

Faraz,

There is a subtle misspelling in Line 3:

$paths='HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstal'

At the end should be Uninstall.

This would affect any 64-bit programs you are searching for.

Also, the ArgumentList parameter will need to be slightly adjusted:

-ArgumentList '/c', $app.uninstallstring

Could be:

-ArgumentList "/c $($app.UninstallString)"

Or you can add another line to account for the string combination:

$processArgs = "/c " + $app.uninstallString
Start-Process -FilePath cmd.exe -ArgumentList $processArgs  -Wait

I was so embarrassed when you pointed out my silly mistake Chance F, however, when I checked my actual script, the location was correct there. Therefore, the mistake occurred while tweaking the text of the script on the textbox, before posting this thread. I have edited the script of the original post.

Thank you for the reply :slight_smile:

I have tried all your suggestions, but no luck as the application didn’t uninstall.

can you print the uninstall string and share here.

C:\Program Files\Notepad++\uninstall.exe

Try -ArgumentList “/c `”$($app.UninstallString)`""

still doesn’t work kvprasoon :frowning:

You can print the uninstall string and check if its happening when you use the same in cmd with elevated permissions. For some applications I’ve seen that uninstall string doesn’t work as is.

Yes, I have tried running uninstall string in command prompt, elevated permissions, and I received UAC prompt in order to proceed the uninstall. So, is there any way to bypass UAC in PowerShell to accomplish this task?

Well, you can’t bypass UAC for an execution. But you can disable(not really recommended) it by updating UAC setting registry key.

To get around UAC, try running the MSIEXEC command . if you run the script as the local SYSTEM account, in that case it shouldn’t ask for UAC and all remote commands are actually running under the SYSTEM account.
So, can use below line in your code and try
Example:
MSIEXEC /quiet /x $($app.uninstallstring)

Yes, I have been searching ways to bypass UAC, but didn’t find any workable suggestion\solution.

Moreover, I was trying to create an answer file in order to capture the inputs from the uninstall process, and thereby executing uninstall.exe, the file where uninstallstring points to, silently. However, I am unsuccessful so far.

Thanks for the post Evila, the suggestion didn’t work. Although the example you gave didn’t return any error in PS ISE or command prompt, the application was still on the computer.

Try this command to silently uninstall Notepad++ (using the “/S” switch - it is case sensitive and must be a capital “S”):

Start-Process -FilePath "$($app.UninstallString)" -ArgumentList '/S' -Wait

Grrr, why doesn’t this work? No error given either.

get-package notepad++* | Uninstall-Package -verbose

This would only work if you installed via MSI. There isn’t an official MSI for Notepad++.

<hr />

On a side note, if you did have an MSI install and you wanted it to uninstall I would suggest running the following first. It would allow you to see the exact name you would need to uninstall the MSI package

get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

Then you enter that exact name where “Software Name” is and the MSI install will be no more.

Get-Package -Name "SOFTWARE NAME" | Uninstall-Package -Force

A workaround for notepad++ I was just given. It won’t be a silent uninstall though.

get-package *notepad* | % { & $_.Meta.Attributes["UninstallString"]}

[quote quote=169705]A workaround for notepad++ I was just given. It won’t be a silent uninstall though.

<textarea class="ace_text-input" style="opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;" spellcheck="false" wrap="off"></textarea>
1
2
get-package *notepad* | % { & $_.Meta.Attributes["UninstallString"]}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote]

Well, you learn to do something in a new and different way. Didn’t realize this could be done in this manner. Thanks

Now just to tie in the Silent uninstall since who wants to look at the uninstaller and just get it done quickly.