Uninstall software from remote computer

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

April 1st, 2014 5:59am

Use the uninstall method for the Win32_Product object.

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

$soft3.Uninstall()

Free Windows Admin Tool Kit Click here and download it now
April 9th, 2014 6:28pm

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
June 11th, 2015 4:16pm

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

Free Windows Admin Tool Kit Click here and download it now
June 12th, 2015 3:26am

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
June 12th, 2015 7:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics