PowerShell: Uninstall Software Remotely


I will need to remove a software from more than 30 Windows 2003 servers once I confirmed it has the memory leaking bug. To make the job easier, I prefer to use script (as always):

$app = Get-WmiObject -Class Win32_Product -ComputerName (Get-Content servers.txt) | Where-Object {$_.Name -match “Software Name”}
$app.Uninstall()

NOTE:

1) Win32_Product WMI class is not enabled on Windows 2003 by default, so you have to install ‘WMI windows Installer Provider’ under ‘Management and Monitoring Tools’ through the Add/Remove Windows components in control panel.

2) If you are not sure the software name, use the this script to do a query first: Get-WmiObject -Class win32_product -ComputerName remote_server_IP

 

 

Advertisement

6 thoughts on “PowerShell: Uninstall Software Remotely

  1. The ‘WMI windows Installer Provider’ can be installed by script too.

    First, copy the following 3 files from the i386 folder to a shared folder
    MSI.MF_
    MSI.MO_
    MSIPROV.DL_

    Second, create a text file named WbemMSI.txt in the same share folder, and type in the following entries.
    [Unattended]
    InstallFilesPath=”\\server\share\file”

    [Components]
    WbemMSI = On

    Third, run the script to install this Windows component ‘ sysocmgr /i:%windir%\inf\sysoc.inf /u:\\server\share\file\WbemMSI.txt ‘

  2. nice one, thanks. It seems that on my windows 7 is no method uninstall!?
    I used this:
    $app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match “Java”}
    $app.Uninstall()

    Method invocation failed because [System.Object[]] doesn’t contain a method named ‘Uninstall’. At line:1 char:15 FullyQualifiedErrorId: MethodNotFound

    I run PS as administrator!

    Any ideas?

  3. hi there, in my case i have change it just a litle and comes to this:
    $app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like “Java”}
    msiexec /x $app.IdentifyingNumber /qn
    and i getting to work , the $app.uninstall() do not work for me eather. Hope this will work for you to.

  4. When i try above command getting some error

    ou cannot call a method on a null-valued expression.
    At line:2 char:1
    + $app.Uninstall()
    + ~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s