Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

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

Reply
 
Old 05-16-2008   #1 (permalink)
tom.luxury


 
 

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

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:
[PowerShell]
"test"> test.a

[Cmd.exe]
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
file?

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.

My System SpecsSystem Spec
Old 05-16-2008   #2 (permalink)
Karl Mitschke


 
 

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

Hello tom,

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

Do this:

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

Karl
Quote:

> 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:
> [PowerShell]
> "test"> test.a
> [Cmd.exe]
> 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
> file?
>
> 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.
>

My System SpecsSystem Spec
Old 05-16-2008   #3 (permalink)
tom.luxury


 
 

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

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
My System SpecsSystem Spec
Old 05-16-2008   #4 (permalink)
Karl Mitschke


 
 

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

Tom;

I have no idea, and i have no idea

Quote:

> 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

My System SpecsSystem Spec
Old 05-27-2008   #5 (permalink)
alexandair


 
 

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

On May 16, 6:36*pm, tom.lux...@xxxxxx wrote:
Quote:

> 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

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:
http://blogs.msdn.com/powershell/arc...he-rescue.aspx

-aleksandar
http://powershellers.blogspot.com

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
zip files created within same month PowerShell
Why are pgm created files, NOT shown in flder dir.? Vista General
Reading the .dmp files created by BSODs Vista performance & maintenance
Files created during upgrade from XP Vista file management
Cannot access files created with XP Vista account administration


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46