Well, I have some clues (maybe the question was stimulated by my thoughts). Yes, this is a kind of trap not only in PowerShell (but PowerShell allows).
Apparently, PowerShell uses ToString() to convert. And it was the wrong assumption that System.IO.FileInfo.ToString() returns FullName . The reflector shows that it returns base.OriginalPath , which is just what was passed in the constructor, not necessarily the full path.
Here is a demo:
Set-Location C:\TEMP\Test [string](New-Object IO.FileInfo File1.txt) [string](New-Object IO.FileInfo C:\TEMP\Test\File1.txt) [string](New-Object IO.FileInfo ./..//Test///..Test\File1.txt) # Output: # File1.txt # C:\TEMP\Test\File1.txt # ./..//Test///..Test\File1.txt
Thus, it seems that the first Get-ChildItem uses only names when creating FileInfo objects, and the second Get-ChildItem with the –Include parameter uses full paths. This is mistake? It looks controversial. This may be a feature, dubious, but still with some basic reasons. I doubt though ...
Roman kuzmin
source share