lundi 3 février 2020

Powershell custom object hidden property types

Background:

I have a PSCustomObject that was created by converting a json array via ... | convertfrom-json. The object has a lot of other objects for the property values (basically it's a collection of a lot of PSCustomObjects). From knowing the object I know it contains at least three different types of of objects (types meaning PSCustomObject with different properties).

Issue:

When running Get-Member I only two object types and their members, the third one is not listed at all. I know there is a third object type as I can select properties that are only available in that object.

Note:

I did have once a similar issue, where some members would only appear in the results of get-member only if called first in a $object | select... method, otherwise they just didn't show up. I didn't figure it out then either. The current issue is not the same but might be related, as I tried the method of $object | select... and it didn't help.

Example:

Exmaple of get-member result

$res.address_objects.ipv4 | gm       


   TypeName: Selected.System.Management.Automation.PSCustomObject
Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
host        NoteProperty System.Management.Automation.PSCustomObject <snip>
name        NoteProperty string name=<snip>
uuid        NoteProperty string uuid=<snip>
zone        NoteProperty string zone=<snip>

   TypeName: System.Management.Automation.PSCustomObject
Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
name        NoteProperty string name=<snip>
network     NoteProperty System.Management.Automation.PSCustomObject <snip>
uuid        NoteProperty string uuid=<snip>

As you can see there is two object types here and they both have some different property names.





Aucun commentaire:

Enregistrer un commentaire