locked
Retrieving all output from remote session with Invoke-Command. RRS feed

  • Question

  • If I remotely invoke the following Powershell script:

    "Starting..."

    $r=1/0

    "Finish"

    With something like this:

    $s = New-PSSession -ComputerName  mycomputer
    $result=Invoke-Command -Session $s -Script  { d:\go.ps1 }  
    $result

    I only get the error message for the division by zero.   The "Starting..." message is lost.

    How can I retrieve all of the output from the remote command in the event of an error?   

    Monday, October 16, 2017 2:45 PM

All replies

  • $result=Invoke-Command  -File d:\go.ps1

    or

    $result=Invoke-Command -Script  {"Starting..."; 1/0}  


    \_(ツ)_/


    Monday, October 16, 2017 2:52 PM