1

I'm trying to get a list of associated instances for a win32_service, and then separate those instances based on whether they "depend on" or are "required by" the win32_service.

For example, I can get a list of associations for the WAS service:

$service = Get-CimInstance -Query "SELECT * FROM win32_service WHERE name='WAS'"
Get-CimAssociatedInstance -InputObject $service -Association "win32_dependentservice"

This allows me to obtain a list of services associated to WAS; however, it doesn't state whether they are "antecedent" or "dependent" objects.

If I use WQL, I can see that the objects are enumerated by antecedent and dependent keys:

Get-CimInstance -Query "SELECT * FROM win32_dependentservice"

And, I can then specify the key when using "associators of"

Get-CimInstance -Query "Associators of {win32_service.name='WAS'} WHERE AssocClass=win32_dependentservice Role=dependent"

Is it possible to specify the "role" in Get-CimAssociatedInstance? Or, am I stuck with using WQL to determine if a service is dependent/antecedent?

EDIT: I specifically want to know if getting this information is possible with Cim cmdlets. I know Get-Service can get the information, but that is not what I am asking here.

Ci3
  • 4,632
  • 10
  • 34
  • 44
  • Any reason you don't use Get-Service? It shows DependentServices and ServicesDependedOn. – TheMadTechnician Nov 05 '14 at 02:30
  • @TheMadTechnician I didn't mention it here, but in my situation I need the StartMode property. Get-Service does not have this. I also want a win32_service type, not a ServiceController type. – Ci3 Nov 05 '14 at 03:06
  • 1
    I wish this question had been answered properly. – Cody Konior Oct 12 '16 at 04:51

1 Answers1

0

I'll put it as an answer. I think the best solution for you would be to use the Get-Service cmdlet. It provides you with the information that you are requesting. Example of usage and output:

PS C:\windows\system32> Get-Service wwansvc|fl


Name                : wwansvc
DisplayName         : WWAN AutoConfig
Status              : Stopped
DependentServices   : {}
ServicesDependedOn  : {wcmsvc, RpcSs, NdisUio}
CanPauseAndContinue : False
CanShutdown         : False
CanStop             : False
ServiceType         : Win32ShareProcess

That shows that nothing depends on it, but that it depends on wcmsvc, RpcSs, and NdisUio.

TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56