trying to output file names that exceed the limit to a document it runs through all the files with no errors but it looks like it skips the long files. I read some where you need to create a PS drive in order to have poweshell get-item that exceeds the length. I know it looks bad
#requires -Version 3 Set-StrictMode -Version Latest set-location $env:USERPROFILE [int]$maxpathlength = 220 $profileRoot = $env:USERPROFILE $paths = ("Documents" , "Desktop") if(!(test-path c:\FLDRRDR)){Md c:\FLDRRDR} foreach($path in $paths){ if(test-path ("$profileRoot" + "\$path")){ Try { $files = Get-ChildItem -Path $path -Recurse -ErrorAction Stop Foreach($file in $files){ if($file.FullName.Length -gt $maxpathlength) { $file.FullName | Out-File c:\FLDRRDR\Long-File-Names-Log.txt -Append } } } Catch{ set-location -Path ("$profileRoot" + "\$path") $root = Get-ChildItem -Directory foreach($subfolder in $root){ set-location -Path ("$profileRoot" + "\$path" + "\$subfolder") new-psdrive -Name X -PSProvider FileSystem -Root ("$profileRoot" + "\$path" + "\$subfolder") x: Try { $files = Get-ChildItem -Path x: -Recurse -ErrorAction Stop Foreach($file in $files){ if($file.FullName.Length -gt $maxpathlength) { $file.FullName | Out-File c:\FLDRRDR\Long-File-Names-Log.txt -Append } } set-location -Path ("$profileRoot" + "\$path" + "\$subfolder") remove-psdrive -name x } Catch{ set-location -Path ("$profileRoot" + "\$path" + "\$subfolder" + "\$subfolder2") remove-psdrive -name x $root2 = Get-ChildItem -Directory foreach($subfolder2 in $root2){ new-psdrive -Name X -PSProvider FileSystem -Root ("$profileRoot" + "\$path" + "\$subfolder" + "\$subfolder2") x: Try { $files = Get-ChildItem -Path x: -Recurse -ErrorAction Stop Foreach($file in $files){ if($file.FullName.Length -gt $maxpathlength) { $file.FullName | Out-File c:\FLDRRDR\Long-File-Names-Log.txt -Append } } set-location -Path ("$profileRoot" + "\$path" + "\$subfolder" + "\$subfolder2") remove-psdrive -name x } Catch{ "OUCH!" set-location -Path ("$profileRoot" + "\$path" + "\$subfolder" + "\$subfolder2") remove-psdrive -name x } } } } } } }