-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Get-ChildItem -Recurse shouldn't quietly ignore -Include and -Exclude when -LiteralPath is used instead of -Path #3730
Copy link
Copy link
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management modulecmdlets in the Microsoft.PowerShell.Management module
Milestone
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)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.The issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management modulecmdlets in the Microsoft.PowerShell.Management module