Last updated: Apr 4, 2024
Reading time·3 min

The Unix tee command reads standard input and writes the output of a program
to standard output and copies it to the specified file.
Use the PowerShell Tee-Object command as the Windows equivalent of the Unix
tee command. The Tee-Object command is used to save the output of a command
in a file or variable and send it down the pipeline.
Open PowerShell and run the following command.
dir | tee my_file.txt

Notice that we can use the tee command in PowerShell.
Tee-Object PowerShell command which is also accessible by its alias - tee.# 👇️ the same as above dir | Tee-Object my_file.txt
The command in the example uses the dir command to display a list of a
directory's files and subdirectories and saves the output of the command in a
file.
You can also specify a path to the file where the command should save the object.
dir | tee -FilePath "C:\Users\Public\bobbyhadz\my_file.txt"

You can use this approach to save the output of any command in a file or a variable.
Get-Process | tee -FilePath "C:\Users\Public\bobbyhadz\my_file.txt"
Note that you can replace tee with Tee-Object in any of the commands above.
You can use the Get-Help Tee-Object command to display the help page of
Tee-Object with information about the syntax, the command's aliases and some
helpful remarks.
Get-Help Tee-Object
You can also check out the command's syntax and some examples in the official docs.
Alternatively, you can use the tee command in Git Bash on Windows.
If you already have git installed, you can search for Git Bash and use the
tee command, otherwise, you have to install git first.
To download git and be able to use Git Bash:
Next.
Next.
Click Next on the screen that prompts you to "Select Start Menu Folder".
On the next screen, you can choose the default editor for Git, e.g.
Notepad, Notepad++ or any other editor you prefer.

Next.

Next.Install button to install git.Once you have git installed, click on the Search field, type "Git Bash"
and start the application.

Now you can use the tee command directly in Git Bash.
dir | tee my_file.txt

If you need to open Git Bash in a specific folder:

Finally, issue the tee command.
dir | tee my_file.txt
You can also specify a path to the file you want to tail.
dir | tee "C:/Users/Public/bobbyhadz/my_file.txt"

Make sure to replace the path from the example with your specific path.
You can learn more about the related topics by checking out the following tutorials: