creating cfg file with odd results

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Shane Lindberg Shane Lindberg 1 year, 2 months ago.

  • Author
  • #28469
    Profile photo of Shane Lindberg
    Shane Lindberg

    I was trying to make a config file to alter a programs behavior

    when I created the file using this method. the file size was twice as large as the next method.

    "UpdateDisable=1" > file.cfg
    "UpdateEnable=0" >> file.cfg

    when I used this method, the file size was half as large as the first method

    Add-Content file.cfg "UpdateDisable=1"
    Add-Content file.cfg "UpdateEnable=0"

    the files seemed the same, but only the second file actually worked as it was supposed to(changed the update settings). Was this because of the difference in size or some other subtle difference in the file structure or how the file was created?

  • #28473
    Profile photo of Bob McCoy
    Bob McCoy

    It's the difference between a Unicode file and an ASCII file. Many output cmdlets use the -Encoding parameter to allow you to explicitly declare the type of output.

    From Get-Help about_redirection ...

        When you are writing to
        files, the redirection operators use Unicode encoding. If the file has a
        different encoding, the output might not be formatted correctly. To
        redirect content to non-Unicode files, use the Out-File cmdlet with its
        Encoding parameter.
  • #28524
    Profile photo of Shane Lindberg
    Shane Lindberg

    Thank you!

You must be logged in to reply to this topic.