Windows Vista Forums

Help! Powershell changes text file sizes??
  1. #1


    Gary Guest

    Help! Powershell changes text file sizes??

    When I run a command with invoke-expression in Powershell, it creates a file
    almost twice as large as the same thing run from command prompt. Can anyone
    tell me what is going on here?

    If I run the following command from a command prompt, I get a 14K text file:



    dfsradmin rg list /attr:RgName,ObjState >> report.txt


    If I run the following command from a Powershell prompt, I get a 27K file:

    invoke-expression -command "dfsradmin rg list '/attr:RgName,ObjState' >>
    report.txt"

      My System SpecsSystem Spec

  2. #2


    Robert Robelo Guest

    Re: Help! Powershell changes text file sizes??

    > Can anyone tell me what is going on here?

    Different encoding. Cmd.exe's redirects stdout to file using the encoding set in chcp.
    PowerShell's redirection operators _always_ use Unicode encoding.

    You can pipe the statement's output to Set-Content or Out-File and use UTF8 or ASCII encoding.

    Get-Help about_Redirection

    --
    Robert

      My System SpecsSystem Spec

  3. #3


    PaulChavez Guest

    RE: Help! Powershell changes text file sizes??

    >> is an append operator, did you make sure to delete the file from the first
    command before running the second? If not twice the size makes sense.

    Otherwise I would explore the encoding as Uwe recommended.

    "Gary" wrote:

    > When I run a command with invoke-expression in Powershell, it creates a file
    > almost twice as large as the same thing run from command prompt. Can anyone
    > tell me what is going on here?
    >
    > If I run the following command from a command prompt, I get a 14K text file:
    >
    > dfsradmin rg list /attr:RgName,ObjState >> report.txt
    >
    >
    > If I run the following command from a Powershell prompt, I get a 27K file:
    >
    > invoke-expression -command "dfsradmin rg list '/attr:RgName,ObjState' >>
    > report.txt"

      My System SpecsSystem Spec

  4. #4


    Robert Robelo Guest

    RE: Help! Powershell changes text file sizes??

    > Can anyone tell me what is going on here?

    Different encoding. Cmd.exe's redirects stdout to file using the encoding
    set in chcp.
    PowerShell's redirection operators _always_ use Unicode encoding.

    You can pipe the statement's output to Add-Content or Out-File and use UTF8
    or ASCII encoding.

    Get-Help about_Redirection

    --
    Robert

      My System SpecsSystem Spec

  5. #5


    Gary Guest

    Re: Help! Powershell changes text file sizes??

    Thanks for the help. I am slowly trying to migrate all my command line &
    batch file admin stuff to Powershell, and I never had to deal with Unicode.

    "Robert Robelo" wrote:

    > > Can anyone tell me what is going on here?
    >
    > Different encoding. Cmd.exe's redirects stdout to file using the encoding set in chcp.
    > PowerShell's redirection operators _always_ use Unicode encoding.
    >
    > You can pipe the statement's output to Set-Content or Out-File and use UTF8 or ASCII encoding.
    >
    > Get-Help about_Redirection
    >
    > --
    > Robert

      My System SpecsSystem Spec

  6. #6


    Larry__Weiss Guest

    Re: Help! Powershell changes text file sizes??

    It would have been nice if
    Get-Help about_Redirection
    had some actual examples. It does not have examples of even simple cases.
    It does mention the opportunity to use Out-File cmdlet, but there are no examples.

    This webpage has examples
    http://ss64.com/ps/syntax-redirection.html

    This article discusses the topic
    http://www.johndcook.com/blog/2008/0...code-or-ascii/

    - Larry


    Robert Robelo wrote:

    > Different encoding. Cmd.exe's redirects stdout to file using the encoding
    > set in chcp.
    > PowerShell's redirection operators _always_ use Unicode encoding.
    >
    > You can pipe the statement's output to Add-Content or Out-File and use UTF8
    > or ASCII encoding.
    >
    > Get-Help about_Redirection
    >

      My System SpecsSystem Spec

Help! Powershell changes text file sizes?? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting results/text of powershell script to a file as it is run markm75 PowerShell 2 03 Sep 2008
How to display screen output to text file in PowerShell Vinod K PowerShell 5 08 Aug 2008
PDF file sizes KeithD Vista General 3 24 Aug 2007
File sizes Sterno@where.com Vista General 2 12 Aug 2007
XPS file sizes?? Arthur Dent Vista General 1 13 May 2007