Out-File: Why should I combine -Append and -NoClobber? Isn't that enough?

I do not see the difference between

... | Out-File -Append 

and

 ... | Out-File -Append -NoClobber 

Both add information to the file, both do not overwrite the contents, and create the file if it does not exist. Still, all examples on the Internet use a combination of -Append and -NoClobber .

Did I miss something?

+6
source share
2 answers

-NoClobber set the FileMode (how the operating system should open the file) to CreateNew (= if the file already exists, an IOException will be thrown) if -Append not specified, in which case it will be set by FileMode to be added (= opens the file if it exists and searches for the end of the file, or creates a new file).

So, for all practical purposes -Append -NoClobber = -Append

+14
source
  • -Append (search end of file and add new content)
  • -NoClobber (run a warning if the file already exists)

Learn More About Microsoft Doc

0
source

All Articles