February 15th, 2016

PowerTip: Send output to file and screen at the same time

Doctor Scripto
Scripter

Summary: Cloud & Datacenter Management MVP, Thomas Rayner, shows how to easily send data to the output of a script.

Hey, Scripting Guy! Question How can I use Windows PowerShell to send the same data that I’m writing to a file to the standard output of my script?

Hey, Scripting Guy! Answer In Windows PowerShell 5.0, use Tee-Object, for example:

PS C:\WINDOWS\system32> Tee-Object -InputObject ‘Some text’ -FilePath ‘C:\temp\some file.txt’

Some text

PS C:\WINDOWS\system32> Get-Content -Path ‘C:\temp\some file.txt’

Some text

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.