I discovered files generated by Powershell are more than twice the
size of plain text files created outside of Powershell.
Here is the test:
echo test> test.b
A 'dir' of these files from a shell reveals:
05/16/2008 09:34 AM 14 test.a
05/16/2008 09:34 AM 6 test.b
*Notice the size of the files.
What's going on? The test.b file is appropriately 6 bytes: "test\r\n"
= 6 chars. Where are the extra 8 chars coming from in the PS-created
The files in any text editor appear identical and Textpad said they
were identical as well.
Then I opened a PS-created file in MS Word 2007 and saw non-printable
chars before each char in the file.
Please help. Thx.
It's not outputting in ASCII. (I beleive it's unicode)
"test" |out-file -Encoding ascii test.c
I was starting to go down that path (unicode vs. ascii), but hadn't
nailed it yet.
Can I make ASCII the default output encoding? Is this wise?
Something that threw me off is $OutputEncoding. Why doesn't
$OutputEncoding show Unicode?
PS C:\> $OutputEncoding
IsSingleByte : True
BodyName : us-ascii
EncodingName : US-ASCII
HeaderName : us-ascii
WebName : us-ascii
WindowsCodePage : 1252
IsBrowserDisplay : False
IsBrowserSave : False
IsMailNewsDisplay : True
IsMailNewsSave : True
EncoderFallback : System.Text.EncoderReplacementFallback
DecoderFallback : System.Text.DecoderReplacementFallback
IsReadOnly : True
CodePage : 20127
I have no idea, and i have no idea :)
There are two major ways to write files in PowerShell — with the Out-
File cmdlet and using the Set-Content cmdlet. Out-File will try to
format the output and text files are written in Unicode by default. We
can change that with -encoding parameter. Set-Content will simply
write the output and use ASCII encoding.
Also, when we pipe output data from PowerShell cmdlets into native
applications, the output encoding from PowerShell cmdlets is
controlled by the $OutputEncoding variable, which is by default set to
ASCII. You could find more details here: