Avatar of Ossie Akaunu
Ossie Akaunu
Flag 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
Powershell* WMIC

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon
Qlemo

The last one looks correct - what's the result?
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
Qlemo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck