error code capture

Welcome Forums General PowerShell Q&A error code capture

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
1 year, 11 months ago.

  • Author
    Posts
  • #57458

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘error code capture’ is closed to new replies.