I have a folder on a server called MyFolder. There are additional folders called MyFolder.1, MyFolder.2, MyFolder.3 etc.
If I run:
gci C:\Sample | ? { $_.Name -like "MyFolder.*" }
I get the expected output:
Directory: C:\Sample
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 16/10/2012 12:16 MyFolder.1
d---- 16/10/2012 12:16 MyFolder.2
d---- 16/10/2012 12:16 MyFolder.3
However if I run:
gci C:\Sample -Filter "MyFolder.*"
I get:
Directory: C:\Sample
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 16/10/2012 12:16 MyFolder
d---- 16/10/2012 12:16 MyFolder.1
d---- 16/10/2012 12:16 MyFolder.2
d---- 16/10/2012 12:16 MyFolder.3
I'm confused on how MyFolder is included in the output. I'd expect the output to be the same.
The online help highlights that the syntax of the filter is based on the provider but I'm unsure what provider is being used in this instance.
Am I missing a fundamental piece of knowledge here? I've attempted to pass a regex string in to the filter e.g "MyFolder\.*"
but this simply returns nothing. I'm sure I'm missing something simple.
I'm running Powershell version 2.
Resolution
Thanks to Roman Kuzmin for pointing out the differences in wildcard matching. The following gives the expected output:
gci C:\Sample\MyFolder.*
I'll be using this syntax for ease in the future to reduce noise in code.