Get-ChildItem Recurse works on PowerShell 5.1 but not on 7.2.1
See original GitHub issuePrerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
I have created simple script to find all files of a given name on my C:\
disk. It is working on Windows PowerShell 5.1, but not on PowerShell 7.2.1.
Create empty file demo-2021-12-20.txt
in C:\ps_test
and run this script.ps1
:
Get-ChildItem -Path "C:\" -Filter "demo-2021*.txt" `
-Recurse -Force -ErrorAction SilentlyContinue |
ForEach-Object {
$output = $_.Name + "`t" + $_.FullName
Write-Host $output
}
Expected behavior
demo-2021-12-20.txt C:\ps_test\demo-2021-12-20.txt
Actual behavior
Line |
1 | Get-ChildItem -Path "C:\" -Filter "demo-2021*.txt" `
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The system cannot find the path specified.
Error details
Error occurs when using PowerShell 7.2.1 but not when using Windows PowerShell 5.1.19041.1320 (same machine).
Environment data
Name Value
---- -----
PSVersion 7.2.1
PSEdition Core
GitCommitId 7.2.1
OS Microsoft Windows 10.0.19042
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
PowerShell Get-ChildItem -recurse error - it blocks at some ...
PowerShell Get -ChildItem -recurse error - it blocks at some of the 256 long directories name - see example to reproduce error -...
Read more >Get-ChildItem - PowerShell
The Get-ChildItem cmdlet gets the items in one or more specified locations. If the item is a container, it gets the items inside...
Read more >Powershell v5 Get-ChildItem -File not working?
Type Get-Command Get-PowerShell | Format-List to see some detail around the ParameterSets and the source DLL. I'm just wondering if something ...
Read more >How to Leverage AWS PowerShell Commands for ...
Learn to get started using the AWS PowerShell tools to manage resources and automate tasks within the AWS environment!
Read more >Get-ChildItem PowerShell Ultimate Guide
Get -ChildItem obtains objects from specified locations. It uses Recurse parameter to get items from all child containers & Depth parameter ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I have found the source of this error. I have paths on my disk that are over 260 characters in length. It was pain to figure it out, but in the end I got it simply by filtering whole disk recursive with “*”. There is issue already for it: https://github.com/PowerShell/PowerShell/issues/16123
Thank you @iSazonov for testing! I’m closing this issue and I’ll test it with 7.3 😃
Start with
Without any of the other parts. I’m guessing there is a problem directory which threw a non-terminating error before and is a terminating error now.
You can try
And that well tell you which directory is causing the problem.