2

我正在尝试使用 PowerShell 中的 7za.exe(7-zip 的独立版本)解压缩存档。基本上,剥离所有服务代码,我的尝试如下所示:

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

  & $pathTo7z $arguments 2>&1

$dist是 ZIP 文件的本地路径。这$targetDir是本地目录的完整路径。

如果我按原样运行它,我的意思是,在本地运行它,不涉及任何远程处理,我可以毫无问题地得到 7za.exe 的输出。就像我从 cmd.exe 运行它一样。

现在,如果我在远程会话中运行它,就会出现问题:

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

  & $pathTo7z $arguments 2>&1
}

当然,我确保远程 PC 上存在 7za.exe,等等。所以,当我以这种方式运行它时,我看到了一个非常奇怪的行为。它可以显示一些 7za.exe 的输出,然后就挂起。一段时间后(足够长,与提取 150 MB zip 所需的时间相比),它输出以下内容:

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.

有时它会恢复运行并输出更多。但更多情况下它无法完成其工作并失败并出现以下错误:

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

那是什么?我应该怎么做才能获得控制台 EXE 输出,就像我在本地运行它时一样?

4

1 回答 1

1

同样,它原来是 ESET NOD32 防病毒软件。只需按照此处描述的步骤操作,它应该可以工作。

摘自那篇文章:

我推荐的解决此问题的方法是在协议过滤 > 排除的应用程序下为 PowerShell 和 PowerShell ISE 添加例外:

在此处输入图像描述

于 2013-12-11T13:00:28.500 回答