How to fix truncated PowerShell output, even when I've specified -width 300

I'm trying to get a list of all the directories and files on an external hard drive, with one fully-qualified directory/file path per line. I'm using PowerShell on Windows 10 to achieve this. This is the PowerShell command I'm using:

Get-ChildItem 'E:\' -Force -Recurse | Select-Object FullName | Out-File -Encoding utf8 "C:\Users\Me\Desktop\listing.txt" -width 300

However, some paths are being truncated in my output. In fact, over 10,000 lines are truncated. Here is an example of one line in my listing.txt PowerShell output file:

E:\Sort\Tech Stuff\2006-2007 CompanyLtd\fsie01-Engineering-Users-User1\Reference\LCID & Language Group by Language\Configuring and Using International Features of Windows Windows 2000 - List of Locale I...

When I browse to this directory in File Explorer (E:\Sort\Tech Stuff\2006-2007 CompanyLtd\fsie01-Engineering-Users-User1\Reference\LCID & Language Group by Language), the file there is called 'Configuring and Using International Features of Windows Windows 2000 - List of Locale IDs and Language Groups.url'. The path of this file is 228 characters long if I haven't miscounted, which should be within acceptable limits.

What am I doing wrong that is truncating the paths in my PowerShell output?


Pipe output to Format-Table commandlet, e.g. as follows:

Get-ChildItem 'E:\' -Force -Recurse | Select-Object FullName | Format-Table -AutoSize

or

(Get-ChildItem 'E:\' -Force -Recurse).FullName | Format-Table -AutoSize

Note that -Width parameter of Out-File cmdlet specifies the number of characters in each line of output. Any additional characters are truncated, not wrapped. However, -Width 300 should suffice in this case.


First you need to make sure Select-Object is not truncated, by using ExpandProperty for a single property

Get-ChildItem 'E:\' -Force -Recurse | Select-Object -ExpandProperty FullName | Out-File -Encoding utf8 "C:\Users\Me\Desktop\listing.txt"

Or by pipe to format-table when there are more properties.
Format-table will select values to display if there is not space enough in console, even with parameters autosize and wrap.
So you will need to pipe to Out-String with width parameter to see it all in console or add width to Out-File to see it all in output file.

Get-ChildItem 'E:\' -Force -Recurse | Select-Object * | Format-Table | Out-String -width 9999

and (

Get-ChildItem 'E:\' -Force -Recurse | Select-Object * | Format-Table | Out-File -width 9999 -Encoding utf8 "C:\Users\Me\Desktop\listing.txt"

or

Get-ChildItem 'E:\' -Force -Recurse | Select-Object * | Format-Table | Out-String -width 9999 | Out-File -Encoding utf8 "C:\Users\Me\Desktop\listing.txt"

)
When values are in a collection/array the output is controlled by $FormatEnumerationLimit
Setting it to -1 means unlimited.

I know this is an old post, but I found it before the answer I was looking for.
So thought I would share my findings.