Skip to content

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

Description

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)

Activity

  1. SteveL-MSFT commented on Nov 1, 2017

    @SteveL-MSFT
    Member

    This appears to be a regression from v5 (repros with v5.1)

  2. nightroman commented on Nov 1, 2017

    @nightroman

    This appears to be a regression from v5 (repros with v5.1)

    From my observations, -Include worked as expected in PS v5 Preview. So something changed exactly in v5 Preview -> v5 RTM.

    I have no data about -Exclude (i.e. regression or not).

  3. added this to the milestone on Nov 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions