Author Posts

March 14, 2015 at 5:03 am

$result = @(1,2,3)
$result | gm

Why GM returns Int32 instead Array in statement above?

March 14, 2015 at 5:23 am

When you send an array to the pipeline, PowerShell pipes in the elements of that array to the next command, one at a time. So Get-Member, in this case, is seeing three separate Int32 objects instead of a single array object.

There are two ways around this. You can wrap the array in yet another array using the unary comma operator, like so:

,$result | Get-Member

Or, you can call Get-Member without using the pipeline input:

Get-Member -InputObject $result

March 14, 2015 at 5:27 am

So in essense anytime I need to check any object for type I can not use results of | gm as reliable information since in cases where objects implements Ienumerable I would not get correct result and I always has to use Get-Member -InputObject instead

March 16, 2015 at 4:50 am

Another way is to use the GetType method of objects: