You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-ChildItem with FileSystem Provider: behaves inconsequent with -Include #3304
Area-FileSystem-Providerspecific to the FileSystem providerIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Agree that this is not intuitive, but it appears to be by design based on the help:
-Include <String[]>
Specifies, as a string array, an item or items that this cmdlet includes in the
operation. The value of this parameter qualifies the Path parameter. Enter a path
element or pattern, such as *.txt. Wildcards are permitted.
The Include parameter is effective only when the command includes the Recurse
parameter or the path leads to the contents of a directory, such as C:\Windows\*,
where the wildcard character specifies the contents of the C:\Windows directory.
get-childitem*-Include *.jpg
Does what you expect.
I'm not familiar with the history of this provider and why this design was chosen. It seems that if -include is used, it implies * if path is not specified.
Good evening Steve,
Thank you very much for your answer and help!, yes, I've noted that it is by design.
But this shouldn't be a reason to not enhance Powershell and wipe out bad design decisions.
Every programming language is great - if it operates as the programmer expect. If it doesn't, it should be fixed.
I even think it's much more important for the most used commands, because they annoy every day.
(In this example, we can not just add -Include *.jpg to an existing command to get what we expect)
I know it's always a problem if existing commands are changed in their old behaviour, but it can easily be solved by offering good release notes and a global switch, for example using #Requires -Version xxx
or a new one: #Uses-Command-Set -Version xxx
Joel Bennett (@Jaykul): The -Filter parameter is no real substitute, unfortunately: its provider-specific wildcard language has legacy quirks and fewer features than PowerShell's, and it is limited to one argument. (That said, if its capabilities are sufficient in a given use case, It is worth using to greatly speed things up.)
-Include is a generic, provider-independent, array-valued parameter, and what makes its current behavior counter-intuitive is that you'd think that the Child in Get-ChildItemimplies that the -Include pattern is applied to *, i.e., all child items, but that's currently not the case. (You do get that behavior if you add -Recurse, but that changes the semantics, obviously).
By contrast, with Get-Item the current behavior makes sense.
It seems that if -include is used, it implies * if path is not specified.
The fact that * is not implied is the cause of the confusion - in Ilya (@iSazonov)'s example, the wildcard is matched against the directory name FIRST, and only THEN to the names of the items in the directory, as one is likely to expect.
In other words: The explicit need to specify * - either in isolation for the current dir., or by appending it to an explicit path being passed to -Path - is what constitutes the pitfall.
Because it took me a while to figure it out, I thought I'd share how to get the desired behavior with -Include / -Exclude (in the absence of -Recurse) currently:
switch to Get-Item from Get-ChildItem - if you don't, any child directories among the included items will output their children, not the child directories themselves.
use * in the absence of a path / append /* to an existing path; e.g.:
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 23, 2023
Area-FileSystem-Providerspecific to the FileSystem providerIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesWG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Activity
SteveL-MSFT commentedon Mar 10, 2017
Agree that this is not intuitive, but it appears to be
by designbased on the help:Does what you expect.
I'm not familiar with the history of this provider and why this design was chosen. It seems that if
-includeis used, it implies*if path is not specified.schittli commentedon Mar 10, 2017
Good evening Steve,
Thank you very much for your answer and help!, yes, I've noted that it is by design.
But this shouldn't be a reason to not enhance Powershell and wipe out bad design decisions.
Every programming language is great - if it operates as the programmer expect. If it doesn't, it should be fixed.
I even think it's much more important for the most used commands, because they annoy every day.
(In this example, we can not just add -Include *.jpg to an existing command to get what we expect)
I know it's always a problem if existing commands are changed in their old behaviour, but it can easily be solved by offering good release notes and a global switch, for example using
#Requires -Version xxxor a new one:
#Uses-Command-Set -Version xxxKind regards, Thomas
SteveL-MSFT commentedon Mar 10, 2017
Bruce Payette (@BrucePay) do you know the history of this?
Jaykul commentedon Mar 11, 2017
What you want is the
-Filterparameter.iSazonov commentedon Mar 11, 2017
Interesting result:
Here key is "a.b"
mklement0 commentedon Mar 11, 2017
Joel Bennett (@Jaykul): The
-Filterparameter is no real substitute, unfortunately: its provider-specific wildcard language has legacy quirks and fewer features than PowerShell's, and it is limited to one argument. (That said, if its capabilities are sufficient in a given use case, It is worth using to greatly speed things up.)-Includeis a generic, provider-independent, array-valued parameter, and what makes its current behavior counter-intuitive is that you'd think that the Child inGet-ChildItemimplies that the-Includepattern is applied to*, i.e., all child items, but that's currently not the case. (You do get that behavior if you add-Recurse, but that changes the semantics, obviously).By contrast, with
Get-Itemthe current behavior makes sense.ditta95aR commentedon Mar 11, 2017
mklement0 commentedon Mar 14, 2017
Ilya (@iSazonov): I suspect you know it, but just to spell it out explicitly:
-Includeand-Excludeoperate on the leaf component of the-Pathvalue (at least with the Filesystem provider).In your case,
a.bis the (implied) leaf component, and wildcard*.*matches it, soGet-ChildItemshows the content ofC:\temp\a.b.(Note that the documentation does a poor job of explaining that.)
Steve Lee (@SteveL-MSFT):
The fact that
*is not implied is the cause of the confusion - in Ilya (@iSazonov)'s example, the wildcard is matched against the directory name FIRST, and only THEN to the names of the items in the directory, as one is likely to expect.In other words: The explicit need to specify
*- either in isolation for the current dir., or by appending it to an explicit path being passed to-Path- is what constitutes the pitfall.SteveL-MSFT commentedon Mar 14, 2017
Michael Klement (@mklement0) that was a typo on my part, I was trying to say
*should be implied to make it useful rather than giving no resultsmklement0 commentedon Mar 28, 2017
Because it took me a while to figure it out, I thought I'd share how to get the desired behavior with
-Include/-Exclude(in the absence of-Recurse) currently:To get what you might expect something like
to do, you must:
switch to
Get-ItemfromGet-ChildItem- if you don't, any child directories among the included items will output their children, not the child directories themselves.use
*in the absence of a path / append/*to an existing path; e.g.:An explanation can be found in this SO answer of mine.
schittli commentedon Mar 29, 2017
Hi mklement0
thank you very much for sharing your work!
btw: It's the best 'chain of evidence' (I don't find the right english term) that the actual implementation is not what we should have.
kind regards, Thomas
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.