Deserialized objects are missing the GetType method in PowerShell 2 and 3 - by Kirk Munro

Status : 


Sign in
to vote
ID 779256 Comments
Status Active Workarounds
Type Bug Repros 2
Opened 2/14/2013 2:58:02 PM
Access Restriction Public


If you receive objects from a call to Invoke-Command, they come back deserialized.  These deserialized objects are missing the GetType method.  GetType should be there on all objects, deserialized objects included (in which case I would expect it to tell me the objects are PSObjects).
Sign in to post a comment.
Posted by Kirk Munro on 12/21/2014 at 2:50 PM
Get-Member reads the lowest derived type name from the PSTypeNames property on the objects that are piped into it. That is how you can check the type name in PS 2/3.
Posted by blabla2 on 12/21/2014 at 12:15 PM
How do I retrieve the type of a Deserialized object in ps2/3 where there's no GetType() method? The Get-Member command can do it.
Posted by Trevor Sullivan [MVP] on 8/14/2013 at 1:36 PM
+1 to Keith Hill's comment. Anything that inherits from System.Object should have GetType().
Posted by Matthew Reynolds [MSFT] on 2/18/2013 at 11:34 AM
+1 on expecting these to implement gettype(). Just last week I was writing a script which needed to understand deserialized objects and I was surprised when gettype() didn't work.

In contrast to Kirk, though, my expectation was that the type would be Deserialized.Foo.Bar as shows up in some places, as opposed to just psobject.

Either would be better than nothing.
Posted by Keith Hill MVP on 2/15/2013 at 9:45 AM
I expect *all* .NET objects to have a GetType() method! That's fundamental to .NET.