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.
bigendianunicode: Encodes in UTF-16 format using the big-endian byte order.
oem: Uses the default encoding for MS-DOS and console programs.
unicode: Encodes in UTF-16 format using the little-endian byte order.
utf7: Encodes in UTF-7 format.
utf8: Encodes in UTF-8 format.
utf8BOM: Encodes in UTF-8 format with Byte Order Mark (BOM)
utf8NoBOM: Encodes in UTF-8 format without Byte Order Mark (BOM)
utf32: Encodes in UTF-32 format.

-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"