I'm new to PowerShell and have a question on the following behaviour. I'm trying to count the number of files in a directory of a certain type. If there are some, I will then copy them elsewhere. Here's the output of my test folder; the code is modified from MSDN examples I found:
[PS]> Get-ChildItem c:\pstdump
Directory: C:\pstdump
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/12/2011 9:48 AM 0 blah.pst
-a--- 2/12/2011 9:36 AM 0 New Text Document.txt
-a--- 2/12/2011 9:36 AM 20 New WinRAR archive.rar
[PS]> (Get-ChildItem c:\pstdump).Count
3
[PS]>
All well and good; PowerShell and I are in agreeance that there are 3 files in the folder. Now when I'd like to pick particular file types (for example .PST files):
[PS]> Get-ChildItem c:\pstdump -filter "*.pst"
Directory: C:\pstdump
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2/12/2011 9:48 AM 0 blah.pst
[PS]> (Get-ChildItem c:\pstdump -filter "*.pst").Count
[PS]>
The '.Count' is returning nothing even though the filter should be returning 1 file. I consider this an incorrect count...
Could someone please explain why this 'incorrect' .Count is being returned?
Alternatively, please feel free to berate me for the obvious n00b mistake I must be making.
Thanks!
