Powershell 远程:如何对错误代码 14 进行故障排除

Powershell remote: How to troubleshoot error code 14

我有一个 powershell 脚本,它将 运行 进行远程长时间测试。测试将 运行 在那里进行几个小时。请参阅下面的代码。

Invoke-Command -ComputerName $remoteIP -Credential $credential -ScriptBlock { 
        param ($runTestFolder,$runtestPath,$testsuiteOption)
        if ($(Test-Path -Path $runtestPath) -eq $false) {
            Write-Error "Run_Test.exe is not found from the path specified. "
            return "ERROR_RUN_TEST.EXE_DO_NOT_EXIST"
        }
        
        cmd /c "cd $runTestFolder && $runtestPath /s $testsuiteOption"

        return "COMPLETED."
    } -ArgumentList $runTestFolder,$runTestPath,$TestSuiteOption

但是大约两个小时后,它抛出了这个错误。我该如何调试它?我检查了“about_Remote_Troubleshooting”,但它根本没有提到错误代码。

Processing data for a remote command failed with the following error message: Error with error code 14 occurred while calling method WSManPluginReceiveResult. For more information, see the about_Remote_Troubleshooting Help topic.

根据 New-SessionOption MS 文档:

The IdleTimeoutMs value of the default Microsoft.PowerShell session configuration is 7200000 milliseconds (2 hours). Its MaxIdleTimeoutMs value is 2147483647 milliseconds (>24 days). The default value of the WSMan shell idle time-out (WSMan:\<ComputerName>\Shell\IdleTimeout) is 7200000 milliseconds (2 hours).


备选方案是:

  • 建立一个New-PSSession setting the IdleTimeout to it's max value and connect to it using the -Session参数:
$pso = New-PSSessionOption -IdleTimeout 2147483647
$pss = New-PSSession $remoteIP -Credential $credential -SessionOption $pso

Invoke-Command -Session $pss -ScriptBlock {
    # script do something
}

Remove-PSSession $pss
$pso = New-PSSessionOption -IdleTimeout 2147483647

Invoke-Command -ComputerName $remoteIP -ScriptBlock {
    # script do something
} -Credential $credential -SessionOption $pso