question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get-ChildItem Recurse works on PowerShell 5.1 but not on 7.2.1

See original GitHub issue

Prerequisites

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 obraz 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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
rafrafekcommented, Dec 20, 2021

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 😃

0reactions
jhoneillcommented, Dec 20, 2021

Start with

Get-ChildItem -Path "C:\" -Filter "demo-2021*.txt"  -recurse

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

Get-ChildItem   -path C:\ -Directory | foreach {write-host $_ ; Get-ChildItem  $_ -filter "demo-2021*.txt" -Recurse} 

And that well tell you which directory is causing the problem.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found