Hello,<\/p>\n
So I have a script<\/p>\n
Get-ChildItem | \n Select FullName, @{N=\"PathLength\";E={$_.FullName.Length}} | \n\tFormat-Table -AutoSize\n<\/code><\/pre>\n
Advertisement
This script displays some paths and the length of these paths.<\/p>\n
I would like to rewrite script in order to:<\/p>\n
\n- \n
Checking partitions for paths (Not file names) exceeding 260 characters without the “Windows” directory<\/p>\n<\/li>\n
- \n
Sorting from longest to shortest path value<\/p>\n<\/li>\n
- \n
Displaying the first 10 in table and saving them to .txt / .csv<\/p>\n<\/li>\n<\/ul>\n
I’ve been tired of this for several hours the script I gave is basic version.<\/p>\n
I modified it in several ways and I didn’t solve problem.<\/p>\n
My ideas are over maybe You have any idea how to do it well.<\/p>\n
I will be grateful for Your help
<\/p>","upvoteCount":7,"answerCount":4,"datePublished":"2020-01-04T19:36:51.000Z","author":{"@type":"Person","name":"spiceuser-ak66l","url":"https://community.spiceworks.com/u/spiceuser-ak66l"},"suggestedAnswer":[{"@type":"Answer","text":"
Hello,<\/p>\n
So I have a script<\/p>\n
Get-ChildItem | \n Select FullName, @{N=\"PathLength\";E={$_.FullName.Length}} | \n\tFormat-Table -AutoSize\n<\/code><\/pre>\nThis script displays some paths and the length of these paths.<\/p>\n
I would like to rewrite script in order to:<\/p>\n
\n- \n
Checking partitions for paths (Not file names) exceeding 260 characters without the “Windows” directory<\/p>\n<\/li>\n
- \n
Sorting from longest to shortest path value<\/p>\n<\/li>\n
- \n
Displaying the first 10 in table and saving them to .txt / .csv<\/p>\n<\/li>\n<\/ul>\n
I’ve been tired of this for several hours the script I gave is basic version.<\/p>\n
I modified it in several ways and I didn’t solve problem.<\/p>\n
My ideas are over maybe You have any idea how to do it well.<\/p>\n
I will be grateful for Your help
<\/p>","upvoteCount":7,"datePublished":"2020-01-04T19:36:51.000Z","url":"https://community.spiceworks.com/t/powershell-too-long-path-finder/745175/1","author":{"@type":"Person","name":"spiceuser-ak66l","url":"https://community.spiceworks.com/u/spiceuser-ak66l"}},{"@type":"Answer","text":"
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.<\/p>\n
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.<\/p>\n
…and as for displaying the first 10 in the table: (select -first 10)<\/p>\n
I’ll leave it to you, to put it together with these … shall we say ‘hints’. Any trouble, let us know.<\/p>\n
Regards,<\/p>\n
Jeff<\/p>","upvoteCount":0,"datePublished":"2020-01-04T23:31:25.000Z","url":"https://community.spiceworks.com/t/powershell-too-long-path-finder/745175/2","author":{"@type":"Person","name":"jeffreycummings","url":"https://community.spiceworks.com/u/jeffreycummings"}},{"@type":"Answer","text":"
should be like<\/p>\n
Get-ChildItem -Recurse -Force | Where-Object {$_.FullName.Length -gt 260}| select Fullname,Name,@{N=\"PathLength\";E={$_.FullName.Length}}|Sort-Object pathlength -Descending\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-01-05T15:05:02.000Z","url":"https://community.spiceworks.com/t/powershell-too-long-path-finder/745175/3","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"When I’ve had to do this in the past, I had to include -ea SilentlyContinue in the original query.<\/p>","upvoteCount":0,"datePublished":"2020-01-06T15:28:41.000Z","url":"https://community.spiceworks.com/t/powershell-too-long-path-finder/745175/4","author":{"@type":"Person","name":"gary-m-g","url":"https://community.spiceworks.com/u/gary-m-g"}}]}}