none
Uninstall software from remote computer RRS feed

  • Question

  • Hi All,

    I confirmed that windows remote management is enable...

    I wanted to create a script to remove software to one of the machine in AD environment but after run my script is nothing happen...

    My scrip as below:

    Import-Module ActiveDirectory
    $Compt= Read-Host "Please enter the Computer Name/ IP Address that need software uninstall"
    $compt1= Get-ADcomputer -filter 'name -like $compt' | select -expand name
    $compt1
    $soft = Read-Host "Please provide the software name you wanted to uninstall (example: Winzip)"
    $soft2= "*$soft*"
    $soft3= Get-WmiObject -Class win32_product -comp $Compt| Where {$_.Name -like "$soft2"}
    $soft4= $soft3 | FL Name, Vendor,version, LocalPackage
    "Please confirm the software you wanted to uninstall:"
    $soft4
    $confirmed= Read-Host "Please copy (right click -> mark -> enter to copy) and paste the local package to proceed uninstallation"
    $arguments = '/x' + $confirmed + "/passive"
    $uninstall= Invoke-expression "msiexec $arguments"
    Invoke-command -computername $compt1 -scriptblock {$uninstall}

    If I remove last 3 line and replace by below command that it works on my own machine but won't work on other remote machine:

    msiexec /x $confirmed /passive

    Please feel free to contact me at kaeinan@yahoo.com

    Tuesday, April 1, 2014 5:59 AM

All replies

  • Use the uninstall method for the Win32_Product object.

    $soft3= Get-WmiObject -Class win32_product -comp $Compt| Where {$_.Name -like "$soft2"}

    $soft3.Uninstall()

    Wednesday, April 9, 2014 6:28 PM
  • OK, but what if I would like to import list of computers from CSV file and then uninstall a particular software from all the clients? How do you suggest about getting this done? Please advise
    Thursday, June 11, 2015 8:14 PM
  • Hi

    You can use the code from Radjin in a foreach-loop. Supposed your .csv file looks like this:

    ComputerName;
    Computer1;
    Computer2;
    Computer3;

    You could use the following code:

    $ComputerList = Import-Csv C:\temp\SampleCsv.csv -Delimiter ';' | select ComputerName -ExpandProperty ComputerName

    foreach ($Computer in $ComputerList)
         {
         $Software= Get-WmiObject -Class win32_product -ComputerName $Computer| Where {$_.Name -match "Adobe Reader"}
         $Software.Uninstall()
         }

    If you have a large number of computers you should use a different approach. One example would be that you do the uninstallations as jobs.

    Cheers

    • Edited by UnitWinGuy Friday, June 12, 2015 7:28 AM
    Friday, June 12, 2015 7:25 AM