1

When running the following Powershell snippet, I get the error Get-Item : Cannot find path 'path' because it does not exist. even though the path in question does exist. As far as I can tell, it only seems to fail when there are two Get-ChildItem piped together.

Get-ChildItem | Get-ChildItem | % { Get-Item $_ }

The following three snippets do work however.

Get-ChildItem | Get-ChildItem | Get-Item
Get-ChildItem | Get-ChildItem | Get-Item | % { Get-Item $_} 
Get-ChildItem | Get-ChildItem | % { Get-Item $_.FullName } 

Both Get-ChildItem and Get-Item return seem to be returning the same object. What is going on here? What am I missing?

Jamie Lester
  • 848
  • 9
  • 20
  • 1
    The problem is that _Windows PowerShell_ situationally stringifies `Get-ChildItem` output objects by file _name_ rather than by full path; the problem has been fixed in _PowerShell [Core] v6.1+_ - see [this answer](https://stackoverflow.com/a/53400031/45375) for details. – mklement0 Jan 06 '21 at 22:47

0 Answers0