Command Prompt and PowerShell most of the times provides some output information i.e. ping results and other details. Often you need to further process these details and share the information with others to get the expert opinion. So rather than copying the text from the command line, you can also directly save the output to a file that is much more convenient to share.
Saving the Command Prompt Output to a File
In case you want to get the output of a command from the Command Prompt or PowerShell, it is very easy with a few simple steps. All you need is to open the command prompt and before executing the command type the name of the file with greater than sign.
It will automatically create the file if the file does not exist. The file will be created in the directory where you are currently in while executing the command. In case you want to save the file to a specific directory then you need to provide the complete path to the folder where you want to save the file along with the file name.
In case you want the results both on a file and display the command results then you need to follow the given structure.
> folder-path\file-name.txt | type
Saving the PowerShell Output to a File
To save the output to a file in PowerShell, you need to follow the same as you do for Command Prompt. All it requires is to add the file name before executing the command.
The same way as the command prompt, it will create a file automatically if the file is not already present. To save the output to the file at a custom location then you need to provide the complete address to the file otherwise it will save the file to the location where you are running the command.
Viewing the content of the file
To view the content of the file, you need to use Get-Content with the path to the file and file name.
Get-Content -Path "path-to-file\file-name.txt"
Note that, it will only save the output to the text file with .txt extension. Also, the formatting is the default and there is no way you can customize it through the command line.
You can also download HOW TO COMPARE THE CONTENT OF FOLDERS USING COMMAND PROMPT