Avatar of jana
jana
Flag for United States of America

asked on 

Error in PowerShell with Get-ChildItem, 'The specified path, file name, or both are too long'

We are practically new PowerShell.  We are working in trying to identify all files that has been modified before 12/8/2015 in Windows 10.

We open PS in the point where wanted to start the task and used the following script:
dir -recurse |  ? { $_.Attributes -like '*Archive*' -and  $_.LastWriteTime -lt $BackupDate} | out-file "c:\p.txt"

Open in new window


After a long time, we get this error message various time:


dir : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the
directory name must be less than 248 characters.
At line:1 char:1
+ dir -recurse |  ? { $_.Attributes -like '*Archive*' -and  $_.LastWrit ...
+ ~~~~~~~~~~~~
+ CategoryInfo          : ReadError: (C:\Users\RIO\D...mision_1_0_0_10:String) [Get-ChildItem], PathTooLongException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

The task finally finishes outputs the result to the c:\p.txt but the files that cause the error messages wasn't included.

Please advice how to go around this problem.
Powershell

Avatar of undefined
Last Comment
Qlemo

8/22/2022 - Mon