The Wayback Machine - http://web.archive.org/web/20220914023419/https://github.com/PowerShell/PowerShell/issues/16695
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-ChildItem with -File and -Exclude parameters causes all files to always be excluded #16695

Open
5 tasks done
ReneRebsdorf opened this issue Jan 4, 2022 · 4 comments
Open
5 tasks done
Labels
Area-FileSystem-Provider specific to the FileSystem provider Needs-Triage The issue is new and needs to be triaged by a work group. WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Comments

@ReneRebsdorf
Copy link

ReneRebsdorf commented Jan 4, 2022

Prerequisites

Steps to reproduce

When using the Get-ChildItem cmdlet, I would expect -File to filter for only files, and when using -Exclude, these files should be possible to further filter. Instead when using the -File and the -Exclude parameters, no files are returned.

The problem is only reproducable with the -File parameter, not the -Directory parameter.

Expected behavior

Given a folder with files "a" and "b", and a folder "subfolder":

If using `Get-ChildItem -File`: Both files should be returned, and the subFolder should not be returned.
If using `Get-ChildItem -Exclude "a"`: File "b" and folder "subFolder" should be returned
If using `Get-ChildItem -File -Exclude "a"`: Only file "b" should be returned

Actual behavior

Given a folder with files "a" and "b", and a folder "subfolder":

If using `Get-ChildItem -File`: Both files are returned, the subFolder should not be returned.
If using `Get-ChildItem -Exclude "a"`: File "b" and folder "subFolder" should be returned

However:
If using `Get-ChildItem -File -Exclude "a"`: No files nor folders are returned.

Error details

No errors are returned

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.1
PSEdition                      Core
GitCommitId                    7.2.1
OS                             Microsoft Windows 10.0.22000
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

@ReneRebsdorf ReneRebsdorf added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jan 4, 2022
@ReneRebsdorf
Copy link
Author

ReneRebsdorf commented Jan 4, 2022

Further testing shows that if using the -Recurse parameter the expected behavior is seen.

@daxian-dbw daxian-dbw added Area-FileSystem-Provider specific to the FileSystem provider WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc. and removed Area-FileSystem-Provider specific to the FileSystem provider labels Jan 4, 2022
@iSazonov
Copy link
Collaborator

iSazonov commented Jan 4, 2022

Add Area-FileSystem-Provider to consider for FileSystem Provider V2.

@iSazonov iSazonov added the Area-FileSystem-Provider specific to the FileSystem provider label Jan 4, 2022
@iSazonov
Copy link
Collaborator

iSazonov commented Jan 4, 2022

For reference #13524

@MichaelZ4714
Copy link

MichaelZ4714 commented May 19, 2022

The bug is still present in PowerShell 7.2.4 on Windows 11.
The correct result is not only returned when adding -Recurse but also when having the wildcard * in the path:
Get-ChildItem * -File -Exclude "a"
But this cant be used for mitigation in all algorithms. As a general solution one has to omit -File and pipe the resulting object to
Where-Object { -not $_.PSIsContainer}
back to pre-3.0 :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FileSystem-Provider specific to the FileSystem provider Needs-Triage The issue is new and needs to be triaged by a work group. WG-Engine-Providers built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Projects
None yet
Development

No branches or pull requests

4 participants