Powershell Select –ExpandProperty [PropertyName]

We use select-object command to get properties from powershell output. Things are always fine with select-object if select the single valued property, but if we select multi-valued property or grouped property, the powershell returns the result as comma-separated values, sometimes the value can not be readable format, in this case, we should use ExpandProperty to expand multi-valued (or grouped) property.

The below command returns the Dependent Services for the windows service EventSystem, the DependentServices property is multi-valued property, so the below command returns value as comma separated values.

 Get-Service | Where-Object {$_.Name -eq "EventSystem"} | Select DependentServices

You can expand the multi-valued property by using –ExpandProperty and get as separated values.

 Get-Service | Where-Object {$_.Name -eq "EventSystem"} | Select -ExpandProperty  DependentServices
Advertisement

Leave a Comment