Using powershell .Uninstall() will not remove the program from the "Programs and features" list in Windows 7

1

I am working on windows 7 64x laptop. and using powershell i wrote the following script to remove multiple programs:-

PS C:\Users\***> $programs = @("Microsoft SQL Server 2014 T-SQL Language Service","Microsoft SQL Server 2014 Transact-SQL ScriptDom")
PS C:\Users\***> foreach($program in $programs)
>> {$app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "$program"}
>> if ($app -ne $Null)
>> {
>> $app.Uninstall()
>> Write-Output "completed"
>> }}
>>

and i got this result:-

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :

completed
__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :

completed

so i thought that the programs were removed successfully. but when i checked the "Control Panel" >> "Programs and Features", i found that the programs are still listed and i am able to uninstall them from their.. so seems my powershell script did not uninstall the applications. so can anyone adivce on this please?

test test

Posted 2019-11-20T22:47:48.133

Reputation: 161

Answers

0

Can you try:

...
if ($app -ne $Null)
{
if ($app.Uninstall().returnvalue -eq 0) { Write-Output "completed" }
else { write-warning "failed to uninstall $program." }
...

Louis

Posted 2019-11-20T22:47:48.133

Reputation: 18 859