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