error code capture

This topic contains 3 replies, has 4 voices, and was last updated by Profile photo of Sonny Puijk Sonny Puijk 3 weeks, 4 days ago.

  • Author
    Posts
  • #57458
    Profile photo of Srikanth Byram
    Srikanth Byram
    Participant

    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
    Profile photo of Robin Haberstroh
    Robin Haberstroh
    Participant

    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
    Profile photo of Daan Weda
    Daan Weda
    Participant

    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
    Profile photo of Sonny Puijk
    Sonny Puijk
    Participant

    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.