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

Doctor Scripto

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

0 comments

Discussion is closed.

Feedback usabilla icon