Instead of using > to redirect the output into a file, pipe it to out-file cmdlet.
The out-file cmdlet allows some useful parameters as follows:
Parameter | Argument | Description |
-Append | Adds the output to the end of an existing file. | |
-Encoding | Encoding | Specifies the type of encoding for the target file. The default value is utf8NoBOM.
The acceptable values for this parameter are as follows: ascii: Uses the encoding for the ASCII (7-bit) character set. |
-FilePath | Path | Specifies the path to the output file. |
To redirecting the output of the dir command to dir.txt file, use the following command:
dir | out-file -encoding ascii -filepath "dir.txt"
Leave a Reply