Powershell get-childitem output formatting Powershell get-childitem output formatting windows windows

Powershell get-childitem output formatting


I know the usual answer is, don't use the format-* cmdlets, since the output can't really be used by other cmdlets, but since this a formatting question, how about something like:

get-childitem -Recurse K:\AppData\*.* -Filter *.model | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-6)} | sort LastWriteTime -descending | format-table LastWriteTime, Name, Directory >> C:\AAA\result.txt

The only downside I can see is if the directory name ends up being too long, you may need to try playing with adding either -Wrap or -AutoSize to the end of the format-table cmdlet.

If neither of those solves the width issue (assuming you even have one), I found a (page)[http://poshoholic.com/2010/11/11/powershell-quick-tip-creating-wide-tables-with-powershell/] about creating really wide tables, so you could end up with something like:

get-childitem -Recurse K:\AppData\*.* -Filter *.model | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-6)} | sort LastWriteTime -descending | format-table LastWriteTime, Name, Directory -AutoSize | Out-String -Width 1024 >> C:\AAA\result.txt


You can re-order the properties with Select-Object (select):

gci -Recurse K:\AppData\*.* -Filter *.model | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-6)} | sort LastWriteTime -descending |Select LastWriteTime,Name,Directory