I need to be able to launch a process and read the output into a variable. Then based on the return of the command I can choose to show the full output or just a selected subset.
So to be clear, I want to launch a text based process (psexec actually) and read the output from that command (stdout, stderr, etc) into a variable rather than have it directly outputted to the console.
You left off some details regarding what kind of process, but I think this article from the Powershell Team Blog has whatever you’d like to do, either from piping the executable’s output somewhere or utilizing
Now that the second option sounds like what you want to do, you can use the
ProcessStartInfo class to feed in
true as the
RedirectStandardOutput property, and then read from the
StandardOutput property of the
Process object to do whatever you want with the output.
StandardError works identically.