How to send command line output to text file on Windows

  • 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:

Open

Start

.

Search for

Command Prompt

, right-click the top result, and choose the

Run as administrator

option.


(Option 1)

Type the following command to export the command output to a text file and press

Enter

:

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


(Option 2)

Type the following command to export the command and append the result to an existing text file, and press

Enter

:

(Option 3) Type the following command to capture and view the output in the console and press

Enter

:

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:

Open

Start

.

Search for

PowerShell

, right-click the top result, and choose the

Run as administrator

option.


(Option 1)

Type the following command to export the command output to a text file and press

Enter

:

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


(Option 2)

Type the following command to capture and append the result to the end of a file and press

Enter

:

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.

Leave a Comment