Have you ever wanted to save the output of a command to a file? The process is simpler and more straightforward than you might think. Saving the output of a command to a file can be incredibly useful for troubleshooting issues, saving system configurations, or even sharing information with others. In this tutorial, we’ll show you a simple way to save command output to a file using Command Prompt and PowerShell. Let’s get started.
Save Command Prompt Output to File
If you are using Command Prompt, you can use the
> operator to export the output to a file. Here’s how.
First, open Command Prompt. To do that, press Start, type Command Prompt, and click on the result.
In the Command Prompt window, type the following command and press Enter to save the output to a text file. Replace “Your-Command” with the command you want to execute. Also, replace the example file path with the actual path where you want to save the text file.
Your-Command > "C:\path\to\text\file.txt"
For example, if you are trying to see all the users and groups on your computer, you can use the
whoami /all command and save its output to a text file. Here’s how the command would look:
whoami /all > "C:\Users\YourUsername\Desktop\user-list.txt"
Note: Some commands may require administrative privileges. In that case, open Command Prompt as admin.
Save PowerShell Output to File
On PowerShell, you can use the
Out-File command with
-FilePath parameter to export the output of a command to a text file.
Start by opening PowerShell. To do that, press the Windows key + X and select Terminal. The terminal on Windows 11 & 10 opens with the PowerShell tab active by default. If it didn’t, click the downward arrow on the terminal’s title bar and select Windows PowerShell.
In the Terminal window, run the following command to save the output to a text file. Don’t forget to replace “Your-Command” with the command you want to execute and the example file path with the actual path where you want to save the text file.
Your-Command | Out-File -FilePath "C:\path\to\text\file.txt"
For example, if you want to export Windows 11 update history, you can run the following command. This will export the output to the WUHistory.txt file on your desktop.
Get-WUHistory | Out-File -FilePath "C:\Users\YourUsername\Desktop\WUHistory.txt"
Note: Some commands may require admin privileges to run. In that case, open Terminal as an admin by right-clicking on the Start icon and selecting Terminal (Admin).