Link to home
Start Free TrialLog in
Avatar of Ossie Akaunu
Ossie AkaunuFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell Uninstall using WMIC

I have a requitrment to uninstall a suite of applications using WMIC. Initially I wanted to use the below script

$ObjApp = Get-WmiObject win32_product -filter "IdentifyingNumber = '$FindAppbyGUID'" -namespace root/cimv2

 If ($ObjApp.Uninstall().ReturnValue -eq 0)
 {
    Write-Host  "Uninstall SUCCESSFULL"
 }
 Else
 {
    Write-Host "Uninstall FAILED"
 }

For whatever reason this application will not uninstall with the above code neither via msiexec /X /qn etc etc.
However the application will uninstall with below WMIC command ...

wmic product where identifyingnumber="{AAAA00A0-BB11-22CC-D333-4E4444E44444}" call uninstall

My method of running this in powershell is ...

$Cmd = "wmic product where identifyingnumber="{AAAA00A0-BB11-22CC-D333-4E4444E44444}" call uninstall"
Invoke-Expression $Cmd

I also tried ...
$Cmd = 'wmic product where identifyingnumber="{AAAA00A0-BB11-22CC-D333-4E4444E44444}" call uninstall'
Invoke-Expression $Cmd

Any Help will be appreciated.

Thank You in Advance
Avatar of Qlemo
Qlemo
Flag of Germany image

The last one looks correct - what's the result?
Avatar of Ossie Akaunu

ASKER

The error message I get is ...
wmic : Unexpected switch at this level.
At line:1 char:1
+ wmic product where identifyingnumber="{63B5DA5A-477B-438D-A6A0-118787 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Unexpected switch at this level.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial