ServiceController.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Outputs a line of a ServiceController
function Write-Color-Service
{
    param ([string]$color = "white", $service)

    Write-host ("{0,-8}" -f $_.Status) -foregroundcolor $color -noNewLine
    Write-host (" {0,-18} {1,-39}" -f (CutString $_.Name 18), (CutString $_.DisplayName 38)) -foregroundcolor "white"
}

function ServiceController {
    param (
        [Parameter(Mandatory=$True,Position=1)]
        $service
    )

    if($script:showHeader)
    {
       Write-Host
       Write-Host "Status Name DisplayName"
       $script:showHeader=$false
    }

    if ($service.Status -eq 'Stopped')
    {
        Write-Color-Service $global:PSColor.Service.Stopped.Color $service
    }
    elseif ($service.Status -eq 'Running')
    {
        Write-Color-Service $global:PSColor.Service.Running.Color $service
    }
    else {
        Write-Color-Service $global:PSColor.Service.Default.Color $service
    }
}