Personally, I no longer use -Include or -Exclude . I always go through the Where-Object . I donβt know if the author of -Include and -Exclude crazy or there were problems with the underlying .Net provider, but they were hacked like hell.
I'm on 5.0.10240.16384.
gci -Path $path -Include *.txt -Force
Returns nothing.
gci -LiteralPath $path -Include *.txt -Force
Returns everything in $path .
gci -LiteralPath $path -Include *.txt -Force -Recurse gci -Path $path -Include *.txt -Force -Recurse
Both return * .txt in $path and all subfolders.
So what should be the right behavior? Does the -Recurse flag -Recurse way -Include works? I dont know. I do not care. I am not going to engage in such behavior. I just use this:
gci -Path $path -Recurse -Force | Where-Object { $_.Extension -eq '.txt' }
I rely on Get-ChildItem to list files and folders and what it is. Just give me the objects and I will filter them out. Like all old Remove-Item -Recurse errors, there is something out there that just doesn't work the way people expect it to.
Bacon bits
source share