How to send command line output to text file on Windows

Yes, you can direct the command output to a text file using Command Prompt and PowerShell.

Command output to file
Command output to file / Image: Mauro Huculak
  • To send command line output to a text file on Windows, open Command Prompt (admin) and run “Command-syntax > C:\Output.txt” or “Command-syntax | tee C:\Output.txt” in PowerShell (admin).

On Windows 11, 10, 8, 7, or even older versions, it’s possible to save a command’s output, and in this guide, I will explain how to complete this process. Usually, you open the Command Prompt or PowerShell, run one or a series of commands, then select and copy the output, create a text file, paste the results, and save the file. Although this is a common approach, it takes a lot of steps. You can also take a screenshot or picture with your phone, but these are not the best ways to accomplish this task.

The correct approach is to append the command syntax you want to run with the correct command that Command Prompt and PowerShell offer to save the output to a text file.

In this guide, I will explain the different methods to save the command output to a text file on virtually any version of Windows.

Save command output to a text file on Windows

On Windows, you can export the command output with different commands depending on whether you use Command Prompt or PowerShell.

From Command Prompt

To save the output of a command from Command Prompt, use these steps:

  1. Open Start.

  2. Search for Command Prompt, right-click the top result, and choose the Run as administrator option.

  3. (Option 1) Type the following command to export the command output to a text file and press Enter:

    Command-syntax > C:\Path\to\Export-results.txt

    In the command, replace “Command-syntax” with the command syntax and specify the path and the name of the text file to save the contents. For example, ipconfig > C:\Export-results.txt

    Command Prompt save output to file

  4. (Option 2) Type the following command to export the command and append the result to an existing text file, and press Enter

    Command-syntax >> C:\Path\to\Export-results.txt
  5. (Option 3) Type the following command to capture and view the output in the console and press Enter:

    Command-syntax > C:\Path\to\Export-results.txt | type C:\Path\to\Export-results.txt

The greater-than > redirect operator makes it possible to redirect whatever the outcome of the command is into a text. You’re not limited to text files. You can also export to “.doc,” “.xls,” and other formats.

If you need to create a list of all the files and folders from a specific location, instead of typing one by one, use this command:

  • Dir /b > C:\Output-file.csv

If you need to create a list of specific types of files, use this command:

  • Dir *.doc/b > C:\Output-file.csv

The asterisk (*) represents any name, the kind of file that you want a list from, and (/b) uses bare format (no heading information or summary).

From PowerShell

To save the command output to a text file from PowerShell, use these steps:

  1. Open Start.

  2. Search for PowerShell, right-click the top result, and choose the Run as administrator option.

  3. (Option 1) Type the following command to export the command output to a text file and press Enter:

    Command-syntax | tee C:\Path\to\Export-results.txt

    In the command, replace “Command-syntax” with the command syntax and specify the path and the name of the text file to save the contents. For example, ipconfig | tee C:\Export-results.txt

    PowerShell save output to file

  4. (Option 2) Type the following command to capture and append the result to the end of a file and press Enter:

    Command-syntax | tee -append C:\Path\to\Export-results.txt

The pipeline operator | and tee commands (short for “Tee-Object”) send the capture of the output to the file while showing the result on the console screen. Also, the -append option prevents overriding an existing file by appending the next output to the end of the file.

About the author

Mauro Huculak is a Windows How-To Expert who started Pureinfotech in 2010 as an independent online publication. He has also been a Windows Central contributor for nearly a decade. Mauro has over 14 years of experience writing comprehensive guides and creating professional videos about Windows and software, including Android and Linux. Before becoming a technology writer, he was an IT administrator for seven years. In total, Mauro has over 20 years of combined experience in technology. Throughout his career, he achieved different professional certifications from Microsoft (MSCA), Cisco (CCNP), VMware (VCP), and CompTIA (A+ and Network+), and he has been recognized as a Microsoft MVP for many years. You can follow him on X (Twitter), YouTube, LinkedIn and About.me. Email him at [email protected].