Two asides:
>>
is a (virtual) alias for Out-File -Append
; if the intent is not to append (to a preexisting file) but to only capture the current command's (entire) output, use just >
/ Out-File
without -Append
.
Out-File
and therefore also >
/ >>
capture the for-display representation of the input objects in a file, which is not suitable for subsequent programmatic processing. For the latter, use a cmdlet that produces structured output, such as Export-Csv
.
That said, it's reasonable to expect Out-File
to capture all for-display data, given that a file rather than the display is the target.
Regrettably, as of PowerShell [Core] v7.0, Out-File
/ >
/ >>
are (still) sensitive to the console (terminal) window's width and capture only as much as would currently fit on the screen.
You can use Out-File
with the -Width
parameter to work around that:
Get-ChildItem -Recurse -File -Filter *.pbix |
Sort-Object -Property LastAccessTime |
Select-object -Property Name, FullName, LastAccessTime, LastWriteTime -Last 10 |
Out-File -Width ([int]::MaxValue-1) files.txt # Add -Append, if needed.
Note: As of v7.0, [int]::MaxValue-1
is seemingly the highest value accepted; [int]::MaxValue
is quietly ignored. Also, be sure not to use such a high value in Windows PowerShell, where each output line is unconditionally right-space-padded to that length, which would result in excessively large files.