How to output IP address to file with powershell "Write-Output" command without null values

I’m trying to write an IP address (It’s just a random test IP I used) to a file using powershell’s Write-Output and it’s writing the IP address to the file but adding null values after every character. Is there any way to do this properly, without the null characters?

enter image description here

>Solution :

I’m not sure why, but Write-Output '' >> aws_hosts seem to produce an UTF-16 file (with at least 2 bytes per character) and then your VS Code tries to interpret it as UTF-8 showing all those \0 paddings as characters of its own.

Try '' | Out-File -Encoding UTF8 -Append aws_hosts instead. That allows to control the output encoding.

Leave a Reply