Powershell generates an unknown character when repeating a file

I am trying to track 3 lines of plain text in a file using Powershell:

echo "#Generated" > psftp.scp echo "put test.txt" >> psftp.scp echo "quit" >> psftp.scp 

Then I use batch mode psftp.exe to run the file (it executes commands in SFTP), but psftp errors do not see the invalid character:

 psftp: unknown command " β– #" 

What am I missing? I can manually print the file in Windows Notepad and it (psftp) works. Regardless of the fact that I change the first line to ( #Generated ), it gets this error with a block symbol in the first part.

I tried to view the file in NotePad ++ w / "Show all characters", but saw only CR and LF at the end of the lines, which is normal.

+4
source share
1 answer

Try using set / add-content instead of redirecting. You may also need to set the encoding.

 "#Generated" | set-content psftp.scp -Encoding Ascii "put test.txt" | add-content psftp.scp -Encoding Ascii "quit" | add-content psftp.scp -Encoding Ascii 
+3
source

All Articles