Fixing the Issue with Invoke-Command and msiexec in Uninstalling TortoiseVNC on a Remote PC using PowerShell
In this article, we'll discuss the issue that can arise when using the Invoke-Command cmdlet in PowerShell to uninstall TortoiseVNC on a remote PC, specifically when the msiexec command is used.
Context
When uninstalling software remotely using PowerShell, we can use the Invoke-Command cmdlet together with the msiexec command to uninstall the software. However, an issue can arise when trying to uninstall TortoiseVNC using this method in MS Internet Explorer (IE).
The Issue
When using the Invoke-Command cmdlet with the msiexec command in PowerShell to uninstall TortoiseVNC on a remote PC in MS Internet Explorer, the uninstallation may not work as expected. The issue arises due to the fact that MS Internet Explorer (IE) has a default security setting that blocks the execution of scripts.
Solution
To solve this issue, we need to modify the security settings in MS Internet Explorer (IE) to allow the execution of scripts. Here are the steps to follow:
- Open MS Internet Explorer (IE).
- Go to
Toolsand thenInternet Options. - Click on the
Securitytab and then select theInternetzone. - Click on the
Custom Levelbutton. - Scroll down to the
Scriptingsection. - Set the
Active Scriptingoption toEnable. - Click
OKto close theInternet Optionsdialog box.
After modifying the security settings in MS Internet Explorer (IE), we can now use the Invoke-Command cmdlet in PowerShell to uninstall TortoiseVNC on a remote PC using the msiexec command. Here's an example of the PowerShell script:
$remotePC = "RemotePCName"
$TortoiseVNCPackageCode = "{A5F0C2B1-1234-1234-1234-BD52B3E8136D}"
Invoke-Command -ComputerName $remotePC -ScriptBlock {
param($TortoiseVNCPackageCode)
$msiexecPath = "msiexec.exe"
$arguments = "/x $TortoiseVNCPackageCode /qn"
& $msiexecPath $arguments
} -ArgumentList $TortoiseVNCPackageCode
In the above script, we first define the name of the remote PC and the package code of TortoiseVNC. Then we use the Invoke-Command cmdlet to run the script block on the remote PC. The script block first defines the path of the msiexec executable and the arguments required to uninstall TortoiseVNC.