Function Set-DependentService { #command retrieves the dependt services for a service and allows user to take start/stop action on them
[CmdletBinding()]
param(
[Parameter(Mandatory = $True)]
[String]$ServiceName,
[Parameter(Mandatory = $True)]
[ValidateSet("Start","Stop")]
[String]$Action
)
BEGIN {}
PROCESS{
$dependentservices = Get-Service $servicename -DependentServices
Foreach ($Service in $dependentservices) {
if ($Action -eq "Start"){
start-service $service
}else{
stop-service $service
} #end else
} #end foreach
} #end process
END {}
}
I’ve created this command and I need help in outputting by Service Name, Status, and start type of each dependent service.