Powershell Uninstall using WMIC

ukpowo used Ask the Experts™
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"
    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
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

The last one looks correct - what's the result?
ukpowoActive Directory Consultant


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
"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
There are some issues with the ticks/quotes when running inside of PowerShell. And the Invoke-Command is not required. This should work:
wmic product where identifyingnumber="'{AAAA00A0-BB11-22CC-D333-4E4444E44444}'" call uninstall

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial