PowerShell function: Test-ConsoleColor provides a visual demonstration of the foreach scripting construct

Test-ConsoleColor is a PowerShell function that I recently wrote to provide a visual demonstration of how to loop through a series of objects in PowerShell using the foreach scripting construct, not to be confused with the ForEach-Object cmdlet.

#Requires -Version 3.0 -Modules Pscx
function Test-ConsoleColor {

    Tests all the different color combinations for the PowerShell console.

    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.

    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.


     Test-ConsoleColor -Color Red, Blue, Green

     Test-ConsoleColor -Paragraphs 7

     Test-ConsoleColor -Milliseconds 300

     Test-ConsoleColor -Color Red, Green, Blue -Paragraphs 7 -Milliseconds 300



    Author:  Mike F Robbins
    Website: http://mikefrobbins.com
    Twitter: @mikefrobbins

    param (
        [System.ConsoleColor[]]$Color = [System.Enum]::GetValues([System.ConsoleColor]),

        [int]$Paragraphs = 5,

        [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

        foreach ($FGColor in $Color) {
            [System.Console]::ForegroundColor = $FGColor
            [System.Console]::Title = "ForegroundColor: $FGColor / BackgroundColor: $BGColor"

            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


The Test-ConsoleColor function shown in this blog article can be downloaded from my PowerShell repository on GitHub.