Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:52:54+00:00 2026-06-14T20:52:54+00:00

In PowerShell, what’s the difference between Out-File and Set-Content ? Or Add-Content and Out-File

  • 0

In PowerShell, what’s the difference between Out-File and Set-Content? Or Add-Content and Out-File -append?

I’ve found if I use both against the same file, the text is fully mojibaked.

(A minor second question: > is an alias for Out-File, right?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:52:55+00:00Added an answer on June 14, 2026 at 8:52 pm

    Here’s a summary of what I’ve deduced, after a few months experience with PowerShell, and some scientific experimentation. I never found any of this in the documentation 🙁

    [Update: Much of this now appears to be better documented.]

    Read and write locking

    While Out-File is running, another application can read the log file.

    While Set-Content is running, other applications cannot read the log file. Thus never use Set-Content to log long running commands.

    Encoding

    Out-File saves in the Unicode (UTF-16LE) encoding by default (though this can be specified), whereas Set-Content defaults to ASCII (US-ASCII) in PowerShell 3+ (this may also be specified). In earlier PowerShell versions, Set-Content wrote content in the Default (ANSI) encoding.

    Editor’s note: PowerShell as of version 5.1 still defaults to the culture-specific Default (“ANSI”) encoding, despite what the documentation claims. If ASCII were the default, non-ASCII characters such as ü would be converted to literal ?, but that is not the case: 'ü' | Set-Content tmp.txt; (Get-Content tmp.txt) -eq '?' yields $False.

    PS > $null | out-file outed.txt
    PS > $null | set-content set.txt
    PS > md5sum *
    f3b25701fe362ec84616a93a45ce9998 *outed.txt
    d41d8cd98f00b204e9800998ecf8427e *set.txt
    

    This means the defaults of two commands are incompatible, and mixing them will corrupt text, so always specify an encoding.

    Formatting

    As Bartek explained, Out-File saves the fancy formatting of the output, as seen in the terminal. So in a folder with two files, the command dir | out-file out.txt creates a file with 11 lines.

    Whereas Set-Content saves a simpler representation. In that folder with two files, the command dir | set-content sc.txt creates a file with two lines. To emulate the output in the terminal:

    PS > dir | ForEach-Object {$_.ToString()}
    out.txt
    sc.txt
    

    I believe this formatting has a consequence for line breaks, but I can’t describe it yet.

    File creation

    Set-Content doesn’t reliably create an empty file when Out-File would:

    In an empty folder, the command dir | out-file out.txt creates a file, while dir | set-content sc.txt does not.

    Pipeline Variable

    Set-Content takes the filename from the pipeline; allowing you to set a number of files’ contents to some fixed value.

    Out-File takes the data as from the pipeline; updating a single file’s content.

    Parameters

    Set-Content includes the following additional parameters:

    • Exclude
    • Filter
    • Include
    • PassThru
    • Stream
    • UseTransaction

    Out-File includes the following additional parameters:

    • Append
    • NoClobber
    • Width

    For more information about what those parameters are, please refer to help; e.g. get-help out-file -parameter append.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In powershell, is there a difference between: ps theProcessName* | kill and kill -processname
In PowerShell, what is the difference between $? and $LastExitCode ? I read about
In Powershell, is there a difference between & .\monkeys.ps1 and & powershell .\monkeys.ps1 ?
In PowerShell 3 if you are searching for a command you could use both,
The powershell guidelines suggest avoiding the use of aliases in scripts, e.g. spelling out
In PowerShell you can use pushd (an alias for Push-Location ) and popd (an
PowerShell provides a simple technique to view the contents of a function, e.g. Get-Content
PowerShell's type extension facility is neat, but I haven't yet figured out the way
In PowerShell you can use the Get-WmiObject cmdlet to grab WMI classes. I have
Using powershell how do you create a content sorce that uses a BDC? Documentation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.