Hello,

So I have a script

Get-ChildItem | 
    Select FullName, @{N="PathLength";E={$_.FullName.Length}} | 
	Format-Table -AutoSize

This script displays some paths and the length of these paths.

I would like to rewrite script in order to:

  • Checking partitions for paths (Not file names) exceeding 260 characters without the “Windows” directory

  • Sorting from longest to shortest path value

  • Displaying the first 10 in table and saving them to .txt / .csv

I’ve been tired of this for several hours the script I gave is basic version.

I modified it in several ways and I didn’t solve problem.

My ideas are over maybe You have any idea how to do it well.

I will be grateful for Your help :slight_smile:

7 Spice ups

Pretty sure you do all this with the return object(s) from get-childitem, if memory serves me, isContainer - is a Boolean value that is $true if it’s a directory (path), and $false if it’s a file.

If by ‘path value’, you mean path name length, you may have to create a separate data field, and sort by the values in that field… probably the most difficult of the challenge.

…and as for displaying the first 10 in the table: (select -first 10)

I’ll leave it to you, to put it together with these … shall we say ‘hints’. Any trouble, let us know.

Regards,

Jeff

should be like

Get-ChildItem  -Recurse -Force  | Where-Object {$_.FullName.Length -gt 260}| select Fullname,Name,@{N="PathLength";E={$_.FullName.Length}}|Sort-Object pathlength -Descending
1 Spice up

When I’ve had to do this in the past, I had to include -ea SilentlyContinue in the original query.