Home Dashboard Directory Help
Search

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


Status: 

Active


13
0
Sign in
to vote
Type: Bug
ID: 779256
Opened: 2/14/2013 2:58:02 PM
Access Restriction: Public
1
Workaround(s)
view
2
User(s) can reproduce this bug

Description

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).
Details
Sign in to post a comment.
Posted by Trevor Sullivan on 8/14/2013 at 1:36 PM
+1 to Keith Hill's comment. Anything that inherits from System.Object should have GetType().

http://msdn.microsoft.com/en-us/library/system.object.gettype.aspx
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.
Sign in to post a workaround.
Posted by Kirk Munro on 2/14/2013 at 2:58 PM
Use Get-Member to see if the object has a GetType method. If not, it is a PSObject that is representing an object that was deserialized from another session.