Search code examples
windowspowershellpowershell-remoting

Powershell remote: How to troubleshoot error code 14


I have a powershell script which will run a long test remotely. The test will be running there for few hours. See code like below.

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

But after about two hours, it throw this error. How do I debug it? I checked "about_Remote_Troubleshooting" but it does not mention the error code at all.

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.

Solution

  • According to New-SessionOption MS Docs:

    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).


    The alternatives are:

    • Establish a New-PSSession setting the IdleTimeout to it's max value and connect to it using the -Session paramater:
    $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