Windows Server TechCenter >
Windows Server Forums
>
Windows PowerShell
>
filter parameter with the filesystem provider specifics?
filter parameter with the filesystem provider specifics?
- gci \ -filter *.ps1 -recurse
where can I get the specifics on using filter parameter with the filesystem provider? For example I was expecting the above command to return all files ending in .ps1 but it also included files like SQLProvider.Types.ps1xml, clearly not ending in .ps1.
All Replies
if you want to list ps1 files in current folder only just type:
dir *.ps1
if you want to list ps1 files in current folder and subfolders use -Include parameter:
dir -include *.ps1 -recurse
[тут могла быть ваша реклама] http://www.sysadmins.lv- Hi Vadims, thanks for the reply. I had tried the -include parameter first, which returned the expected results but very slowly... then I read a bit from 'man gci -full' where it recommended using the -filter parameter for performance reasons... the provider is supposed to do the filtering when using -filter and only return results whereas with -include the provider first returns all, then powershell filters by the -include criteria.... but the syntax for the -filter criteria is what I'm after (which is provider specific), because *.ps1 returns more than I expect, although more than twice as fast as -include.
- Hi,
As a workaround, please try to test the following command.
gci -filter *.ps1 | ? {$_.name -like "*.ps1"}
Thanks.
This posting is provided "AS IS" with no warranties, and confers no rights. - thanks Mervyn. That is a fine work-around and I appreciate that. What I am really hoping to find out though is what the specific semantics of the -filter switch are for the filesystem provider?
For example:
* = any number of characters (from my experience this doesn't work like the old DOS or CMD wildcard)
? = any one character
others = ?
is it using a regular expression syntax maybe?
etc..
anyone know where to get these specfics? - Hi,
Parameter accepts <string>, wildcards expression is available but Regular Expression cannot be used. Regarding wildcards please refer to the following article.
Supporting Wildcards in Cmdlet Parameters
http://msdn.microsoft.com/en-us/library/aa717088(VS.85).aspx
Regular Expression can be used only when parameter accept <string[]>, such as "select-string –pattern"
However, you reminded me, the result of "gci –filter ? or multiple ?.ps1" is different from ""gci –filter *.ps1".
Thanks.
This posting is provided "AS IS" with no warranties, and confers no rights. - Hi, thanks for the info. I checked out http://msdn.microsoft.com/en-us/library/aa717088(VS.85).aspx for info on wildcard specifics. The description there matches what my understanding was, which would mean there is a bug, or, how the filesystem provider uses them is different... that article was not specific to the filesystem provider, or the -filter parameter of gci though, so I don't know.
but according to that description:
gci \ -filter *.ps1 -recurse
should return only files that end in .ps1, but it also includes .ps1xml and presumably .ps1AnythingElse
so is this a known bug? Or is it simply that the filesystem provider has specific 'filter' syntax for use with the -filter parameter of gci... the latter is what I would guess, considering the help page for gci mentions that: "the syntax of the filter, including the use of wildcards, depends on the provider."
so where is this provider-specific syntax?

