0

I am trying to store the names of all the dependent services of the Windows service "Spooler" with the code below...

'''

$service_name = 'Spooler'
$dependent_services = @()

Get-Service -Name $service_name -DependentServices | ForEach-Object {
    $dependent_services += $_.Name
}

Write-Host $dependent_services

'''

It works the output is shows below...

'''

Fax

'''

But when I tried to achieve the same with the Select-Object CmdLet with the -InputObject and -Property option as shown below, I got empty result.

'''

$service_name = 'Spooler'
$dependent_services = @()

$service = Get-Service -Name $service_name

Select-Object -InputObject $service -Property DependentService | ForEach-Object {
    $dependent_services += $_.Name
}

Write-Host $dependent_services

'''

I have looked into Microsoft documentation also, but not no example was provided on how to use the Select-Object CmdLet with the -InputObject option.

Please help.

Thanks

anbocode
  • 53
  • 6
  • `-InputObject` from `Select-Object` is a property that is meant to be bound exclusively from pipeline. See the linked duplicate for ref – Santiago Squarzon May 10 '22 at 02:09

0 Answers0