tags:

views:

59

answers:

2

Someone knows for which strange reason Powershell doesn't show de 'tee'd' variable in the following snippet?

# a.txt contains any text 
cat a.txt | tee -variable foovar | % { 'value of foovar: ' + $foovar } 

In practice, I'd like to do, in only one line, a search for some text and then, based on the results, process the text, for example send a mail with it:

get-content [somefile] | select-string [somePattern] | tee [var] | ..[more processing] | .\sendmail.ps1 [var] 
+1  A: 

Since all output that was passed into Tee-Object has to be available in the variable the cmdlet caches its input and writes it to the variable at the end.

But you can just as well do the following:

$var = gc a.txt
$var | your_processing_stuff
Joey
A: 

You might use -OutVariable as well

cat c:\dev\NamingConventions.txt -OutVariable test1 | % { write-host 'value: ' $_ }
$test1
cat c:\dev\NamingConventions.txt | select-string -patt panel -OutVariable test2
$test2
stej