When querying for the properties of a Power Shell object, I want to know if the properties listed have child properties that might provide me useful info, but neither the Get-Member command nor the Select-Object -ExpandProperty parameter offer me a way to get that information for all the properties up front.
For instance, if I execute a "Get-Member -MemberType Property" command against an instance of an X509 certificate object, I get a list of 18 properties including "Archived", "Extensions", "FriendlyName", etc.
Most of those properties do not have child properties, but at least one - the "Extensions" property - does.
In turn, some of those child properties have their own child properties.
I need to get all that info up front on one query, not experiment with each one to see if I discover something interesting.
Is there a way to get this info or has someone written a query that will display all the child properties of top-level properties?
I've looked around quite a bit and not found anything.
I tried scripting out a query, but thus far it has not produced good results.
Thank you.
I usually accomplish what you seek simply by converting to json.
By default,
ConvertTo-Jsonhave a depth of 4 elements. Since you only want the top properties and their child, you can reduce the-depthto2.Here's a partial look at the resulting query:
(I only pasted a small snippet)
You can easily see the properties such as Extensions, their child properties and the associated values.
Additional note
If you omit the
-depthparameter forConvertTo-Json, it will recurse to a depth of 4.The depth is configurable up to 100 levels. That being said, some object will have properties that recurse upon the object, so unless needed, you should not unnecessarily put the maximum value there.