forked from mikefrobbins/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest-ConsoleColor.ps1
92 lines (68 loc) · 2.47 KB
/
Test-ConsoleColor.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#Requires -Version 3.0 -Modules Pscx
function Test-ConsoleColor {
<#
.SYNOPSIS
Tests all the different color combinations for the PowerShell console.
.DESCRIPTION
Test-ConsoleColor is a PowerShell function that by default iterates through
all of the possible color combinations for the PowerShell console. The PowerShell
Community Extensions Module is required by the function.
.PARAMETER Color
One or more colors that is part of the System.ConsoleColor enumeration. Run
[Enum]::GetValues([System.ConsoleColor]) in PowerShell to see the possible values.
.PARAMETER Paragraphs
The number of latin paragraphs to generate during each foreground color test.
.PARAMETER Milliseconds
Specifies how long to wait between each iteration of color changes in milliseconds.
.EXAMPLE
Test-ConsoleColor
.EXAMPLE
Test-ConsoleColor -Color Red, Blue, Green
.EXAMPLE
Test-ConsoleColor -Paragraphs 7
.EXAMPLE
Test-ConsoleColor -Milliseconds 300
.EXAMPLE
Test-ConsoleColor -Color Red, Green, Blue -Paragraphs 7 -Milliseconds 300
.INPUTS
None
.OUTPUTS
None
.NOTES
Author: Mike F Robbins
Website: http://mikefrobbins.com
Twitter: @mikefrobbins
#>
[CmdletBinding()]
param (
[ValidateNotNullOrEmpty()]
[System.ConsoleColor[]]$Color = [System.Enum]::GetValues([System.ConsoleColor]),
[ValidateNotNullOrEmpty()]
[int]$Paragraphs = 5,
[ValidateNotNullOrEmpty()]
[int]$Milliseconds = 100
)
if ($Host.Name -ne 'ConsoleHost') {
Throw 'This function can only be run in the PowerShell Console.'
}
$BG = [System.Console]::BackgroundColor
$FG = [System.Console]::ForegroundColor
$Title = [System.Console]::Title
foreach ($BGColor in $Color) {
[System.Console]::BackgroundColor = $BGColor
Clear-Host
foreach ($FGColor in $Color) {
[System.Console]::ForegroundColor = $FGColor
[System.Console]::Title = "ForegroundColor: $FGColor / BackgroundColor: $BGColor"
Clear-Host
Write-Verbose -Message "Foreground Color is: $FGColor"
Write-Verbose -Message "Background Color is $BGColor"
Get-LoremIpsum -Length $Paragraphs
Start-Sleep -Milliseconds $Milliseconds
}
}
[System.Console]::BackgroundColor = $BG
[System.Console]::ForegroundColor = $FG
[System.Console]::Title = $Title
Clear-Host
}