If you don’t have a software deployment tool, such as PDQ Deployment, uninstalling programs from a remote computer could be quite painful. And once again, here is where PowerShell shines.

First of all, let’s see how to get a list of installed programs on a remote computer:

Get-WmiObject Win32_Product -ComputerName $computername | Select-Object -Property IdentifyingNumber, Name

To find a specific program installed on a remote computer:

Get-WmiObject Win32_Product -ComputerName $computername | Where-Object {$_.IdentifyingNumber -eq $number}

Now, let’s uninstall that program.

(Get-WmiObject Win32_Product -ComputerName $computername | Where-Object {$_.IdentifyingNumber -eq $number}).Uninstall()

To avoid the error message when trying to uninstall a non-existed program.

$ComputerName = 'Computer'
$number = '{AC76BA86-1033-FFFF-7760-0E1108756300}' #Adobe Acrobat ID
$adobe = Get-WmiObject Win32_Product -ComputerName $ComputerName | Where-Object {$_.IdentifyingNumber -eq $number}
if ($adobe) { $adobe.Uninstall()
else { $number + ' is not installed on ' + $ComputerName

How about installing a program on a remote computer? That’s a bit more complicated and depend on the install package. If it’s an MSI package or a package that has a silent option, PowerShell should be able to take care of it.

If the install package is already on the remote computer,

Invoke-Command -ComputerName $computer -ScriptBlock { Start-Process 'c:tempsetup.exe' -ArgumentList '/slient' -Wait

But if not, you will need to copy the package over first and then run the installation process.

Here is a more complete example:

$computer = 'computer1'
$session = New-PSSession -ComputerName $computer
Copy-Item -Path '\serversoftwaresophosetup.exe' -ToSession $session -Destination 'c:windowstempsophossetup.exe' -Force
Invoke-Command -Session $session -ScriptBlock { Start-Process 'c:windowstempsophosSetup.exe' -ArgumentList '--quiet' -Wait Move-Item -Path 'c:windowstempsophossetup.exe' } 

I took the Sophos software as an example but you should get the idea.

Finally, thought to mention that in order to get the PowerShell scripts to work on remote computers there are two prerequisites that need to be met.

  • WinRM needs to be enabled on the remote computer
  • You need proper credentials to run the script on the remote computer.

The post How To Remotely Uninstall and Install A Program using PowerShell appeared first on Next of Windows.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: