When using Get-ChildItem to list all files in a folder and its subfolders, it returns the “PathTooLongException” error. This happens when the file path is more than 260 characters.
There are several ways to work around this issue. See this Technet Wiki.
Personally, I found the Get-FolderItem.ps1 script is the easiest one.
- Download the script from Microsoft Script Center Repository
- Right-click on the script and select Properties, then click Unblock
- Launch a PowerShell session
- Load the Get-FolderItem function into the session by entering “. <path>\Get-FolderItem.ps1”. (make sure there is a space between the “.” and the script)
- Enter “Get-FolderItem –Path <path>” to list all files in the folder and its subfolders
- Another use case “Get-FolderItem –Path <path> | Where {$_.LastWriteTime –gt “MM/DD/YYYY” } | Select FullName | Ft –autosize | Out-File c:\temp\modified.file.log.txt –width 4096”
For more information about the Get-FolderItem.ps1 script, see this.