PowerTip "Find dependent services"

by Jun 2, 2011

To get the value of a property there are several ways to get the result

example

Get-Process vmnat | Select-Object -ExpandProperty modules



(Get-Process vmnat).modules

 

Both lines give me the same result, but in the following example the first line works, the second does not

Get-Service spooler |

  Select-Object -ExpandProperty dependentservices |

  Select-Object -ExpandProperty status


((Get-Service spooler).dependentservices).status

 

 

When I have a look at the members

(Get-Service spooler).dependentservices | get-member

 

Then I can see, that the Status property has {get;} at the end. Is this the reason to handle it differently? How has it to be handled then?


I have figured out that the following line will give me also the result

 

(Get-Service spooler).dependentservices | ForEach-Object {$_.status}

 

But I am still curious why

((Get-Service spooler).dependentservices).status

does not work.