February 23rd, 2013

PowerTip: Easily Send Output to Both the PowerShell Console and a Variable

Doctor Scripto
Scripter

Summary: Learn how to send output to both the Windows PowerShell console and to a variable.

Hey, Scripting Guy! Question How can I easily send Windows PowerShell output to both the console and to a variable?

Hey, Scripting Guy! Answer Use the Tee-Object cmdlet and specify a variable name, as shown here.

PS C:\> gps | select name -Last 1 | Tee-Object -Variable a

Name

—-

ZeroConfigService

 

PS C:\> $a

Name

—-

ZeroConfigService

>

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.