Search code examples
powershellpowershell-2.0output-buffering

Powershell: How to capture output from the host


I am using powershell to automate some tasks related to checking out/merging in TFS. When I call

tf get * /recurse

I get a bunch of data scrolling by about the files that are getting checked out. The last line generated by this command (assuming its success) is one telling the checkin number. I would like to parse this out so it can be used later on in my script.

I know that I can do something like

$getOutput = tf get * /recurse

but then the output is suppressed entirely and I want the output of that command to be scrolled in realtime. I would basically like to grab everything that just got sent to the output buffer.


Solution

  • Try something like this:

    tf get * /recurse | tee-Object -Variable getOutput