error code capture

This topic contains 3 replies, has 4 voices, and was last updated by  Sonny Puijk 1 year, 8 months ago.

  • Author
  • #57458

    Srikanth Byram

    hi ,

    i'm running .exe file on a remote machine with sysinternals i.e. psexec.exe. in powershell

    i need to capture the error code of it . can you share an example to do it .

  • #57464

    Robin Haberstroh

    The following command shows some details on capturing or redirecting command output. Based on what you've mentioned, the 2> option may be applicable to what you are looking for.

    get-help about_redirection
  • #57496

    Daan Weda

    Did not test it but maybe something like this.
    Store the output in an variable and return this, you don't have to use the return in PS just output the variable is enough but I put it there to make it more clear.

    $Capture= invoke-command -ComputerName Computer -ScriptBlock 
                                                               $output = psexec.exe
                                                               return $output
  • #57512

    Sonny Puijk

    Grabbing output from psexec is a pain in the ass. Last time I checked (admittedly a long time ago so I might be wrong) it wasn't possible at all.

    You're better off using Invoke-Command to initiate whatever remote command you want to.

You must be logged in to reply to this topic.