One caveat I realized today when trying to create a file using Out-file in powershell.
The command is simple enough:
dir c:\temp\*.exe | Out-file c:\test.txt -append
After that, I used for loop in command prompt to process the txt file
for /f %a in (c:\test.txt) do @echo %a
Guess what? Nothing happened! The above command does not work as it should!
This is due to the encoding used by Out-file. The default encoded in unicode, which the batch command could not read. So if you intend to generate a file for tools like batch commands to process, you must ensure that the encoding is correct.Using this command will make the txt file readable by the FOR command later.
dir c:\temp | Out-file c:\test.txt -append -Encoding "default"