first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

PowerShell 1.0 Script: Toggle-Service; Start-Service, Stop-Service, Write-Host

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.";
}

}

mod date: 2009-03-29T22:18:40.000Z