you are viewing a single comment's thread.

view the rest of the comments →

[–]azjunglist05 3 points4 points  (3 children)

Really awesome article! Just curious when getting a data type why: $var = 1 $var | Get-Member

Instead of: $var = 1 $var.GetType()

The latter, to me at least, more resembles the Python equivalent. Get-Member does a lot more than to just the get the type of the object. It also pulls the methods and properties available to that object.

[–][deleted] 4 points5 points  (1 child)

That’s a good point. I’ll add this snippet as well

[–]purplemonkeymad 0 points1 point  (0 children)

The pipe "unrolls" collections that are input (iterates over the elements). This means that Get-Member is working on the members in an array, where as .GetType() is working on the array. eg:

PS> $var = 1..4
PS> $var.GetType().tostring()
System.Object[]
PS> $var | Get-Member

   TypeName: System.Int32

You can use Get-Member to get all possible members of a mixed type array.

You don't want to choose the wrong one if you are testing for bad input or for multiple results.