1

In Powershell, redirection to file can be done with eith > or out-file, and from what I read > is basically a shortcut for the latter. The problem is that, by default, out-file wraps lines at the width of the screen, so long lines get wrapped pointlessly.

I know I can pass -width to out-file to change the length of a line, however this is getting tedious everytime I want to redirect to file, so is it possible to set defaults for out-file such that I can set the width arbitrarily high, and not have to worry about it again (at least for locally-running scripts on my own box).

2 Answers 2

2

If you are using powershell 3.0 or higher you can set a default width with $PSDefaultParameterValues.

The syntax would be $PSDefaultParameterValues=@{"Out-File:Width"="10000"} to set the default width to 10000.

More information about $PSDefaultParameterValues can be found in the help page for about_Parameters_Default_Values.

Edit: This article explains how to customize your powershell window, including the width of the screen. You could use this approach to set the logical window width to an arbitrary value which would presumably solve your line wrapping issue.

2
  • This works, but setting a large value has several undesirable side effects including hard to read tables, unexpectedly long lines, and some performance issues. Dec 3, 2013 at 6:06
  • Ta. Also thanks @Jason for the caveat; the most serious issue there is potentially performance. For me the others are a non-issue as this is where my text editor takes the strain.
    – Callie J
    Dec 10, 2013 at 9:19
1

Try using Set-Content instead of Out-File. (Or Add-Content for appending.)

1
  • This was a great suggestion for those of us that use PowerShell on macOS, this was the only option that actually worked Oct 13, 2023 at 15:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .