I have Windows 7 and PowerShell 4.0. When exporting content to a file the -Width
parameter does not format based on the given setting. Here is a sample of what I am trying to do:
"It is a nice hot sunny day" | Out-File -FilePath ".\output.txt" -Encoding ASCII -Width 10
The result of the export is not truncated at 10th character. It does not get truncated at all. I cannot figure out what's wrong.
This came as somewhat of a surprise to me, but apparently, the
-Width
parameter only works with formatted objects:String(s) as input, no effect
Format-Table
, this worksFormat-List
, this works, but in a strange manner:So, the closest we can get is propably with
Format-Table -HideTableHeaders
:Inspired by @Matt's answer, you could write your own function to truncate strings: