PowerShell – How to Fix Truncated Output with -width 300

command linepathpowershellwindows

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?

Best Answer

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.

Related Question