Search code examples
powershellpowershell-remoting

Running console EXE from PowerShell: different behavior in output in local and remote sessions


I'm trying to unzip an archive with 7za.exe (stand-alone version of 7-zip) from PowerShell. Basically, striping out all service code, my attempt looks like this:

  [string]$pathTo7z = "$env:TEMP\7za.exe"
  [Array]$arguments = "x", $dist, "-o$targetDir"

  & $pathTo7z $arguments 2>&1

The $dist is a local path to the ZIP file. The $targetDir is a full path to the local directory.

If I run it as is, I mean, locally, without any remoting involved, I get the output of 7za.exe with no problem. It's just the same as if I run it from cmd.exe.

Now, the problem pops up if I run it in a remote session:

....
Invoke-Command -Session $s -ScriptBlock {
  ....
  [string]$pathTo7z = "$env:TEMP\7za.exe"
  [Array]$arguments = "x", $dist, "-o$targetDir"

  & $pathTo7z $arguments 2>&1
}

Of course, I make sure the 7za.exe exists on that remote PC, etc. So, when I run it this way, I see a very strange behavior. It can show me some output of 7za.exe, and then just hangs. After some period of time (long enough, compared to the time required to extract a 150 MB zip) it outputs the following:

WARNING: The network connection to MyServer has been interrupted. Attempting to reconnect for up to 4 minutes...
WARNING: Attempting to reconnect to MyServer ...
WARNING: The network connection to MyServer has been restored.

Sometimes it resumes running and outputs some more. But more often it can't finish its job and fails with the following error:

Processing data for a remote command failed with the following error message: The WinRM client cannot process the request. The encrypted 
message body has an invalid format and cannot be decrypted. Ensure that the service is encrypting the message body according to the 
specifications. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OperationStopped: (MyServer:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : JobFailure
    + PSComputerName        : MyServer

What's that? What should I do to get the console EXE output just like I do when I run it locally?


Solution

  • Again, it turns out to be ESET NOD32 antivirus. Just follow the steps described here, and it should work.

    Excerpt from that article:

    My recommended way of resolving this issue is to add exceptions for PowerShell and the PowerShell ISE under Protocol filtering > Excluded Applications:

    enter image description here