If I can offer an improvement
Function Restart-ServicesAndDependents {
param(
$ServiceName
)
$service = get-service -computer $Server $ServiceName
Restart-Service -InputObject $service -Force -Confirm:$False -verbose
# Get Dependent services - stop each of those
$Dependents = $service.DependentServices
ForEach ( $depService in $Dependents ) {
$DepServiceName = $depService.Name
$StartMode = (Get-WmiObject Win32_Service -filter "Name='${DepServiceName}'").StartMode
if ( $StartMode -ne "Auto" ) {
continue
}
if ( $depService.Status -ne "Running" ) {
Start-Service -InputObject $depService -Confirm:$False -verbose
}
}
}
This grabs the dependent services, and starts those up as well. This is handy if you are hitting a service which has dependencies - in which case, Restart-Service alone will not start those back up, but it will stop them. So you have e.g. Dhcp which has WinHttpAutoProxySvc as a dependent. This will ensure WinHttpAutoProxySvc is started up after.