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
35
# 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:GetChildItemColorTable.Service["Stopped"] $Service
    }
    elseif ($Service.Status -eq 'Running')
    {
        Write-Color-Service $Global:GetChildItemColorTable.Service["Running"] $Service
    }
    else {
        Write-Color-Service $Global:GetChildItemColorTable.Service["Default"] $Service
    }
}