Get-ChildItem2 to list files and folders greater than 260 characters

This function is built using pinvoke and PowerShell to provide a means to list all files and folders that have a character limit greater than 260 characters. This doesn't provide a complete replacement for Get-ChildItem as it doesn't have filtering yet for attributes, but that

 
 
 
 
 
(0)
3,754 times
Add to favorites
Storage
10/22/2015
E-mail Twitter del.icio.us Digg Facebook
  • Files in long folders on a UNC path do not get found
    1 Posts | Last post June 15, 2019
    • If you use the function on a UNC path instead of a local or mapped drive it does not work on long path. Solution is to change the path from \\server\share\path to \\?\UNC\server\share\path.
      
      To solve this I changed this block:
              If (-NOT $Path.StartsWith('\\')) {
                  $Path = "\\?\$($Path)"
                  $SearchPath = "\\?\$($SearchPath)"
              }
      
      Modified:
              If (-NOT $Path.StartsWith('\\')) {
                  $Path = "\\?\$($Path)"
                  $SearchPath = "\\?\$($SearchPath)"
              } Else {
                  $Path = "\\?\UNC\$($Path.substring(2,$Path.length-2))"    # Mod for long folders
                  $SearchPath = "\\?\\UNC\$($SearchPath.substring(2,$SearchPath.length-2))"    # Mod for long folders
              }
      
      
      Also I added a line above the line
                          $Fullname = ([string]$FullName).replace('\\?\','')
      
      Modified:
                          $Fullname = ([string]$FullName).replace('\\?\UNC\','\\')    # Mod for long folders
                          $Fullname = ([string]$FullName).replace('\\?\','')
      
      
      I hope this servers you to and this mod and the mod for large files find the way into this script here.
  • does not work with PowerShell remote session?
    2 Posts | Last post October 27, 2018
    • I copy and pasted the get-childitem2 function into my .ps1 file and run the .ps1 file in remote powershell session with Invoke-Command -FilePath , and I see the following exception. The script runs well locally.
      
      Unable to find type [WIN32_FIND_DATA]: make sure that the assembly containing this type is loaded.
          + CategoryInfo          : InvalidOperation: (WIN32_FIND_DATA:String) [], RuntimeException
          + FullyQualifiedErrorId : TypeNotFound
          + PSComputerName        : theRemoteComputerName
      
    • it's might not related to PowerShell remote session. I got the same error run locally on that machine.
  • File size issues
    2 Posts | Last post September 01, 2017
    • Hi, please let me know if I'm mistaken, but for large files I'm getting odd size (length) reports.
      Windows Explorer size: 5,140,809 kb
      get-Item length:       5,264,188,416 bytes
      Get-Childitem length:  5,264,188,416 bytes
      Get-Childitem2 length:   969,221,120 bytes?
      It appears to work fine for small files ~1,000,000 bytes in size.
    • This has been fixed by a helpful person in Stack Overflow:
      https://stackoverflow.com/questions/45832198/powershell-get-childitem2-size-over-3-5gb
      It appears to be files over 3.5GB to be more accurate. Simply update the script as per the accepted answer, and it'll work fine.