Login with Facebook

Friday, May 15, 2009

Uninstall Products using Powershell

I am trying to uninstall a product I have recently added to my Windows and i tried to access the normal way of uninstallation

which you can go Control Panel\Programs\Programs and Features

image

The problem is that the product I am trying to uninstall is not displayed there, although the product is available in the start menu

image

So I will use Powershell and WMI to uninstall it

gwmi win32_product

image

gwmi win32_product -filter "name='HP ProtectTools Security Manager'"

image

now I will try to find what is the available methods that we can use with this class

I can write gwmi win32_product -filter "name='HP ProtectTools Security Manager'" |gm or gwmi win32_product |gm

image

to call a method you have attach your command to a variable then call the varable.method()

to attach it to variable type $varname=the command

$product=gwmi win32_product -filter "name='HP ProtectTools Security Manager'"

Now we can attach Uninstall method to the variable

$product.uninstall()

this should work fine but as I am tring this example on Windows 7 it gave me return value of 1603 it means some thing that is not 0 (normal exit)

image

I investigated the problem and I found as usual the application is running under non elevated privilege I should select Run as Administrator.

image

I did so and I tried the command again and it gave me return value of Zero.

image

Article Code

1 $product=get-wmiobject win32_product -filter "Vendor='Hewlett-Packard'"
2 $product.uninstall()

No comments:

Post a Comment