The following command wraps the output to the width of the window from which the script was called. That is, the output file is "word"-wrapped. How can I prevent this wrapping in the output file w/o modifying the script?
PS C:\Users\User1> & '\\fileServer\c$\PowerShell Scripts\herScript.ps1' > output.txt
Try this (I can't test it)
Instead of using
>
, which isout-file
, you can useset-content
Use the Write-Host cmdlet as the last statement of your pipeline. Normal unadorned powershell output appears to look at the dimensions of the parent console window, and trims/wraps output lines to width-1. The Write-Host cmdlet bypasses this step and writes directly to stdout without any further munging.
Here's an example, which reads a JSON file, and writes javascript output which adds the JSON to a big string (preserving comments):
Here's a sample input file:
And the output when using Write-Host:
And finally, an example of the terrible things which happen if you leave out the Write-Host cmdlet (assuming a console width of 60):