0

There seems to be a difference between these two uses of Get-ChildItem.

Get-ChildItem -File -Path 'C:\SVN\SSIS\AtomicLoad\Atomic_NPI\*.dtsx'
Get-ChildItem -File -Path 'C:\SVN\SSIS\AtomicLoad\Atomic_NPI' -Filter '*.dtsx'

They both report using Get-Member that they produce TypeName: System.IO.FileInfo.

However, using the -Filter parameter causes Get-Content to look for the file Name in the current working directory.

Get-ChildItem -File -Path 'C:\SVN\SSIS\AtomicLoad\Atomic_NPI' -Filter '*.dtsx' |
    ForEach-Object { Get-Content -Path $_ }

Whereas, not using -Filter has Get-Content looking for the $_.FullName which works.

Get-ChildItem -File -Path 'C:\SVN\SSIS\AtomicLoad\Atomic_NPI\*.dtsx' |
    ForEach-Object { Get-Content -Path $_ }

Why is this?

lit
  • 14,456
  • 10
  • 65
  • 119
  • It's a good question that the linked post hopefully answers - in short: In Windows PowerShell, the stringification behavior of `System.IO.FileInfo` instances regrettably depends on the specifics of the `Get-ChildItem` command through which they were obtained - PowerShell _Core_ no longer has that problem. – mklement0 Mar 01 '19 at 21:54
  • 1
    Thanks, @mklement0. I tried on 6.1.1 and it seems to be working as expected. – lit Mar 01 '19 at 23:33
  • I would consider your approach bad practice anyway. Either use `$_.FullName` in situations like that, or remove the `ForEach-Object` and have `Get-Content` read the input from the pipeline. – Ansgar Wiechers Mar 02 '19 at 11:01

0 Answers0