PowerShell Get-ChildItem full path is truncated

Viewed 2536

I'm capturing the file full path and last modified date in a text file but few directories with longer path gets truncated. Is it possible to get the full path without truncation or ....

Code I used:

Get-ChildItem -Path "\\server\xyz_data\devdata\fail logs\xxx\yyy\2012\01june2012\" -Recurse |
    select -Property Filename, LastWriteTime |
    Out-File -Encoding Ascii -Append d:/file.txt

Output:

server\xyz_data\devdata\fail logs\xxx\yyy\2012\01june2012\text123..... 22/03/2012 11.23.00

Is there any restrictions on number of characters to captured?

2 Answers

Actually, because of the spaces in between the parameters like - recurse, and the missing hyphen in the Out-File cmdlet, your code should not run at all.. Also, I think you mean FullName instead of filename.

Try

Get-childitem -Path "\\server\xyz_data\devdata\fail logs\xxx\yyy\2012\01june2012\" -Recurse | 
    Select-Object -Property FullName, LastWriteTime |
    Export-Csv -Path 'd:/file.csv' -Force -NoTypeInformation

P.S. I used Export-Csv to output the results to file

I assume it's fullname, not filename. It seems like out-file pipes it through format-table first, and depending on the width of your window will truncate the filename. Out-file also encodes in unicode. Export-csv is the way to go. Interestingly, piping to set-content instead would save it as hashtables.

Related