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
| cls
#######################################################################################
Function Write-Color([String[]]$Text, [ConsoleColor[]]$ForeGroundColor, [ConsoleColor[]]$BackGroundColor) {
for ($i = 0; $i -lt $Text.Length; $i++) {
$Color = @{}
if ($ForeGroundColor -and $BackGroundColor){
$Color = @{
ForegroundColor = $ForeGroundColor[$i%($ForeGroundColor.count)]
BackgroundColor = $BackGroundColor[$i%($BackGroundColor.count)]
}
} elseif ($ForeGroundColor) {
$Color = @{
ForegroundColor = $ForeGroundColor[$i%($ForeGroundColor.count)]
}
} elseif ($BackGroundColor) {
$Color = @{
BackgroundColor = $BackGroundColor[$i%($BackGroundColor.count)]
}
}
Write-Host $Text[$i] @color -NoNewLine
}
Write-Host
}
#######################################################################################
$services = Get-WmiObject -Class Win32_Service
Foreach ($objItem in $services) {
if($objItem.State -eq 'Stopped'){
write-color "$($objItem.DisplayName)" , " $($objItem.State)" -ForeGroundColor Yellow,Red
}
else
{
write-color "$($objItem.DisplayName)" , " $($objItem.State)" -ForeGroundColor Yellow,Green
}
} |
Partager