Function Toggle-Service([String] $name, [String[]] $dependents = @()) { $s = Get-Service $name;
if ($s)
{
Write-Host -BackgroundColor Green -ForegroundColor White "Service"$s.Name"found.";
if ( $s.Status -eq "Stopped" )
{
Write-Host -BackgroundColor Gray -ForegroundColor White -NoNewline "Service is stopped.";
Write-Host -BackgroundColor Green -ForegroundColor White " Starting service…";
Start-Service -Name $s.Name;
foreach($dname in $dependents)
{
Write-Host -BackgroundColor Green -ForegroundColor White "Starting dependent Service"$dname"…";
Start-Service -Name $dname;
}
}
else
{
Write-Host -BackgroundColor Green -ForegroundColor White -NoNewline "Service"$s.Name"is running.";
Write-Host -BackgroundColor Gray -ForegroundColor White " Stopping service…";
Stop-Service -Name $s.Name -Force;
}
}
else
{
Write-Host -BackgroundColor Red -ForegroundColor White "Service not found.";
}
}