helpers/Service.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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
Add-Type -AssemblyName System.ServiceProcess function Write-ColorizedServiceLine { param ( [Parameter(Mandatory = $true, Position = 1)][String] $color, [Parameter(Mandatory = $true, Position = 2)] $service ) $defaultColor = $Global:ColorSettings.Service.DefaultColor; Write-HostColor -Value ("{0,-8}" -f $_.Status) -ForegroundColor $color -NoNewline; Write-HostColor -Value ( " {0,-28} {1,-59}" -f (Get-StringCharacters $_.Name 28), (Get-StringCharacters $_.DisplayName 58) ) -ForegroundColor $defaultColor; } function Write-ServiceHeader { if (($Global:ColorSettings.Service.Header.Visible -eq $false) -or ($Script:showHeader -eq $false)) { return; } Write-Host; $textColor = $Global:ColorSettings.Service.Header.TextColor; $separatorsColor = $Global:ColorSettings.Service.Header.SeparatorsColor; Write-HostColor -Value "Status Name DisplayName" -ForegroundColor $textColor; Write-HostColor -Value "------ ---- -----------" -ForegroundColor $separatorsColor; $Script:showHeader = $false; } function Write-Service { param ( [Parameter(Mandatory = $true, Position = 1)] $service ) Write-ServiceHeader; if ($service.Status -eq 'Stopped') { Write-ColorizedServiceLine $Global:ColorSettings.Service.Status.Stopped.Color $service; } elseif ($service.Status -eq 'Running') { Write-ColorizedServiceLine $Global:ColorSettings.Service.Status.Running.Color $service; } else { Write-ColorizedServiceLine $Global:ColorSettings.Service.DefaultColor $service; } } |