We help IT Professionals succeed at work.

Powershell Uninstall using WMIC

ukpowo
ukpowo asked
on
1,239 Views
Last Modified: 2017-04-05
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
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

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

Author

Commented:
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
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION