How to Save Command Output to File using CMD or PowerShell?
Command Output may be useful in future to save time on your system. Windows 10 and 11 support the feature of Saving the Command output from the Command Prompt and PowerShell. Exporting the command output helps to fix the troubleshooting within a time by just applying it. If you want to save command output to a file using Command Prompt or PowerShell then it’s for you.
Command Output to File using the Command Prompt
The steps to save a file in CMD will help to save your time and make it easy to see the text file anytime. Here are the steps to save the command output in a text file with the CMD.
- Run the CMD as an Administrator.
- Type the command that you want to run and the name-of-file.txt there at the end before hitting Enter for your command.
- Your command like ‘system info’ and change the path with your current or own specified location on your desktop.
The Structure Looks Like Your-Command> C:\PATH\TO\FOLDER\OUTPUT.txt
Example of this command: systeminfo>C:\color_monitor.txt
- Optional, to view the results of the saved command output you can press the Enter: YOUR-COMMAND > C:\PATH\TO\FOLDER\OUTPUT.txt in the cmd.
- Replace ‘YOUR-COMMAND’ with your command line and “c:\PATH\TO\FOLDER\OUTPUT.txt” with the path and file name to save the command output.
Here’s how you can manage the output of a command into a file. These are the steps to save a file in CMD. With this, you can easily record the output of a shell command and view it from the Command Prompt. This output will be saved in the .txt file in your Windows.
Command Output to File using the PowerShell
Like on Command Prompt you can use the features to save a Copy of the Output of a Command in PowerShell too. For that, you need to follow a certain procedure to record the output of the shell command.
- Search for the PowerShell in your Windows search.
- Right-click on the PowerShell and click on the Run as administrator option there.
- Now type the command which you want to run and add the text >name-of-file.txtbefore hitting after your primary command.
- Its format, YOUR-COMMAND | Out-File -FilePath c:\PATH\TO\FOLDER\OUTPUT.txt
- Replace ‘YOUR-COMMAND’ with your command line and “c:\PATH\TO\FOLDER\OUTPUT.txt” with the file and path name where you want to save it in the .txt file.
- This process will record the output of a shell command in PowerShell.
- Optional, to view the results of the command output you can enter the given, Get-Content -Path C:\PATH\TO\FOLDER\OUTPUT.txt
- Here too, replace the “c:\PATH\TO\FOLDER\OUTPUT.txt” with your new or desired path and name on it.
How to Manage the output of a command into a file?
From the PowerShell and CMD, you can manage the output file easily by giving a certain file command and with the name and path to save it in a .txt file.
Similarly, To save the output file in CMD you can use the command YOUR-COMMAND > c:\PATH\TO\FOLDER\OUTPUT.txt