Powershell lists properties of properties

I have a command that collects information from the device register:

PS C: \ windows \ system32> Get-PSDevice serverA

HostName: ServerA
OOB:
Severity: Normal
IsVirtual: True

etc.

Some of them have an array of "helper properties" inside, for example:

Cluster: @ {Url = https://ps-apps.com/DeviceRegister/API/Clusters/62 ; VCenterUrl = https://ps-apps.com/DeviceRegister/api/VCenters/2 ; Clustered = 62; VCenterId = 2; Name = Vcenter 1 ABC Prod; DataCenterUrl = https://ps-apps.com/DeviceRegister/api/DataCenters/3 ; DataCenter =; IsValidated = True; IsExceptionCluster = False; SupportsProdWorkloads = False; SupportsNonProdWorkloads = False; SupportsSqlWorkloads = False; ManagedByabc = False}

I can get any property inside the aray that I want to use, for example:

(Get-PSDevice ServerA).cluster.name

I am trying to figure out a way to list all the helper properties using a foreach statement to populate the value.

What would be the best way to achieve this?

+3


source to share


1 answer


Every object in PowerShell has a hidden property .PSObject

that tells you about the object. One of its properties is a property .Properties

(as PetSerAl points out, it is not a property, but in fact MemberSet

, although you are referring to it with property semantics).

(Get-PSDevice ServerA).cluster.PSObject.Properties

      



This will return objects [PSProperty]

that will show you information about the properties (name, value, type, getting and setting it, etc.).

+2


source







All Articles