PowerShell remotely script to uninstall OfficeScan

Abdulaziz ALHAKMANI 35 Reputation points
2023-05-30T10:19:11.9766667+00:00

I want to uninstall micro trend agent from multiple computers on one time remotely because difficult to delete it manually one by one computer. I search on inter I got some script but when run this script show errors Script: SServers = Get-content "C:\scripts\test.txt"

2 EForeach ($Server in $Servers)t

3 EInvoke-Command -ComputerName $Server -ScriptBlock f

4 [(Get-Package -Name "Trend Micro Officescan Agent=" | Uninstall-Package -ErrorAction Silentlycontinue)]) message Errors: C:\scripts\uninstall remotly.ps1

[Abdulaziz-AL-HA] Connecting to remote server Abdulaziz-AL-HA failed with the Following error message " winRM cannot complcte the operation. Verify that the specified

netoriimits

and that firewal1 exception for the winRM service is enabled and allows access from this

computer name 15 valid,, that the computer

accessible over the

computer. By default,, the WinRM firewall exception For public profiles

access to remote computers within the same local subnet. For more information, see the

about_ Remote Troub1 eshooting Help top1c.

: OpenError: (Abdulaziz-AL-HA:String) [], PSRemotingTransportException

CategoryInf

FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken

Windows for business Windows Client for IT Pros User experience Remote desktop services and terminal services
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Khaled Elsayed Mohamed 1,335 Reputation points
    2023-06-07T12:09:46.4533333+00:00

    Hi

    Before running the script, make sure to replace the following placeholders:

    Replace "Computer1", "Computer2", "Computer3" with the names or IP addresses of the target computers. You can add more computer names to the array if needed.

    Replace "{GUID_of_Trend_Micro_Agent.msi}" with the actual GUID of the Trend Micro Agent MSI file. You can typically find the GUID in the registry under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall key.

    Ensure that you have PowerShell remoting enabled on the remote computers, and that you have the necessary administrative privileges to execute remote commands.

    When you run the script, it will iterate through the list of computers, connect to each computer remotely, and execute the uninstallation command for the Trend Micro agent. It will provide output indicating the success or failure of the uninstallation process on each computer.

    the script

    
    
    $computers = "Computer1", "Computer2", "Computer3"  # Replace with the names or IP addresses of the target computers
    
    $uninstallScript = {
        # Uninstall Trend Micro agent
        $uninstallArgs = "/S /v/qn"
        $uninstallCommand = "msiexec.exe /x {0} {1}" -f "{GUID_of_Trend_Micro_Agent.msi}", $uninstallArgs
        Start-Process -FilePath "cmd.exe" -ArgumentList "/c", $uninstallCommand -Wait
    }
    
    # Loop through the list of computers
    foreach ($computer in $computers) {
        Write-Host "Uninstalling Trend Micro agent from $computer"
        try {
            # Invoke the script block on each remote computer
            Invoke-Command -ComputerName $computer -ScriptBlock $uninstallScript -ErrorAction Stop
            Write-Host "Uninstallation completed successfully on $computer"
        } catch {
            Write-Host "Failed to uninstall Trend Micro agent on $computer. Error: $($_.Exception.Message)"
        }
    }
    
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.