Skip to content

Get-ChildItem -Recurse shouldn't quietly ignore -Include and -Exclude when -LiteralPath is used instead of -Path #3730

@mklement0

Description

@mklement0

Even without using wildcards, Get-ChildItem -Recurse allows matching items on every level of the target hierarchy, possibly filtered with -Include and -Exclude.

However, if you use -LiteralPath rather than the (implied) -Path parameter, -Include and -Exclude are quietly ignored:

If there's a good reason for this behavior (none that I'm aware of), then at the very least a warning about -Include / -Exclude getting ignored should be issued, or a separate parameter set should prevent combining -LiteralPath with -Include / -Exclude.

Steps to reproduce

Get-ChildItem              $PSHOME -Recurse -Exclude *   # implies -Path $PSHOME
Get-ChildItem -LiteralPath $PSHOME -Recurse -Exclude *

Expected behavior

Both calls should yield no output, because all items should be excluded by virtue of -Exclude *.

Actual behavior

The 2nd command, due to -Exclude * getting ignored, outputs the entire subtree of $PSHOME.

Environment data

PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on macOS 10.12.4
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Microsoft Windows 10 Pro (64-bit; v10.0.14393)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions