I have six .txt files in a directory. So, I create a variable thus:
$foo = gci -Name *.txt
$foo
is now an array of six strings. In my case I have
PS > $foo
Extensions.txt
find.txt
found_nots.txt
output.txt
proteins.txt
text_files.txt
PS > $foo.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
PS > $foo.Count
6
I'd like to measure that object, so I pass it to Measure-Object:
PS > $foo | Measure-Object
Count : 6
Average :
Sum :
Maximum :
Minimum :
Property :
That's what I was expecting. However, I might also pass $foo
like this:
PS> Measure-Object -InputObject $foo
Count : 1
Average :
Sum :
Maximum :
Minimum :
Property :
That's not what I was expecting. What's going on here?
$foo[0].getTYpe()
$foo = gci -Name *.txt
followed by$foo[0].gettype().Name
givesString
$foo = gci -Filter *.txt
instead then$foo[0].gettype().Name
givesFileInfo
-Name
is a switch that tellsgci
to only return the name. The*.txt
is actually-Path *.txt