Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

Files created by Powershell are over 2X bigger than files created by text editor or cmd.exe.

Skip to first unread message

May 16, 2008, 12:07:41 PM5/16/08
I'm trying to build telnet scripts using Powershell and run them with
the Telnet Script Tool (TST) but files created by Powershell are not
recognized as valid text/script files by TST.

I discovered files generated by Powershell are more than twice the
size of plain text files created outside of Powershell.

Here is the test:
"test"> test.a

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.

Karl Mitschke

May 16, 2008, 12:14:42 PM5/16/08
Hello tom,

It's not outputting in ASCII. (I beleive it's unicode)

Do this:

"test" |out-file -Encoding ascii test.c


May 16, 2008, 12:36:51 PM5/16/08
That did the trick! Thank you Karl.

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

Karl Mitschke

May 16, 2008, 3:13:03 PM5/16/08

I have no idea, and i have no idea :)


May 27, 2008, 6:06:13 AM5/27/08

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:


Oct 22, 2013, 9:43:41 PM10/22/13
Thank you Tom and Karl, 5 years later, spend a week with 6GB file that was doubling in size when we did some formatting with powershell. Took a week for us to find your post !!! But you fixed it !!

Sep 21, 2016, 10:39:16 PM9/21/16
8 years later and still paying dividends!

I've spent several hours trying to figure out why my truncated files were larger than their source... And then I stumbled on this post!

Thanks Karl and Tom!!

Apr 8, 2020, 12:09:12 AM4/8/20
12 years later in 2020 checking in, THANK YOU FOR THIS ANSWER.

Ryan Tusia

Nov 5, 2021, 2:18:26 PM11/5/21
Great friggin' answer. Simply amazing. Thank you!
0 new messages