Services problem with command

Hi everyone

$requiredServices = (Get-WmiObject -Class Win32_DependentService | Where-Object { $_.Antecedent -eq $service.Name }).Dependent

why this command doesnt work?
I want to get all requiredservices for $service.Name and list them in console. Can someone help me?

Hi, welcome to the forum :wave:

You’ve not provided enough information.

What do you mean by ‘doesn’t work’? Do you get any error messages?
How are you defining $service? That’s not included in your code.
What version of PowerShell are you using? WMI cmdlets are not available in PowerShell, only Windows PowerShell (you should be using Get-CIMInstance in both).

Please provide your full code and error messages, formatted as code (see below), and maybe we can get to the bottom of it.

How to format code on

1 Like

Welcome to the forum. :wave:t4:

Why not using pure PowerShell?

Get-Service -Name $service.Name |
    Select-Object -ExpandProperty RequiredServices