Skip to content

Get-ChildItem: -Exclude filters out all items when an excluded name matches the current directory name #26750

@sangafabrice

Description

@sangafabrice

Prerequisites

Steps to reproduce

PS> New-Item -Path '@flowtyped' -Type Directory
PS> Set-Location '@flowtyped/'
PS> New-Item -Path '@flowtyped' -Type File
PS> New-Item -Path 'flow-typed','build' -Type File

Expected behavior

`-Exclude` should filter only matching items and return the remaining files:

PS> "$pwd"
C:\@flowtyped
PS> Get-ChildItem . -Exclude '@flowtyped'

    Directory: C:\@flowtyped

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            2/5/2026  6:51 AM              0 build
-a---            2/5/2026  6:54 AM              0 flow-typed

Actual behavior

No items are returned when the excluded name matches the current directory name:

PS> "$pwd"
C:\@flowtyped
PS> Get-ChildItem . -Exclude '@flowtyped'
PS> # Nothing is returned
PS> Get-ChildItem . -Exclude '@flowtyped','build'
PS> # Nothing is returned


However, using `-Exclude` together with `-Name` produces the expected filtered results:

PS> Get-ChildItem . -Exclude '@flowtyped' -Name
build
flow-typed
PS> Get-ChildItem . -Exclude '@flowtyped','build' -Name
flow-typed


When using `Get-ChildItem` with the `-Exclude` parameter, no results are returned if one of the excluded names is identical to the current working directory name — even when other non-excluded files exist.

This behavior appears inconsistent because combining `-Exclude` with `-Name` returns the expected results.

Error details

Environment data

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerNeeds-TriageThe issue is new and needs to be triaged by a work group.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions