#requires -version 2.0 param ( [Parameter( ValueFromPipeline=$false, Position=0, Mandatory=$True, HelpMessage="Enter a service name like spooler.")] [String]$service, [Parameter( ValueFromPipeline=$false, Position=1, Mandatory=$false, HelpMessage="Enter a computername. The default is the local computer.")] [String]$computername=$env:computername ) #make sure you run this in an elevated PowerShell session function Get-Required { #requires -version 2.0 Param([string]$name,[string]$computername) $errorActionPreference="SilentlyContinue" Get-Service -Name $name -computername $computername -requiredServices | foreach { #write the service name to the pipeline write $_ Get-Required $_.name $computername #filter out duplicates based on displayname } | select displayname -unique | foreach { #then get the re-get the service object Get-Service -DisplayName $_.displayname -computername $computername } } #end function #main script body try { Get-Service -Name $service -computername $computername -ea stop | Out-Null Get-Required $service $computername } catch { Write-Warning "Failed to find service $service on $computername" } Finally {}