PowerShell ISE Environment Keyboard Shortcuts, Part 2

A coworker asked how many of these shortcuts I knew.  Given that I had to go looking for a shortcut that was explicitly displayed in the Edit menu, I guess you know the answer.  Then, he said he wished he could learn them.  That gave me an idea…

Oh, and to save you the trouble, I’ve attached the script to generate the .CSV, Word and PDF docs of the shortcuts in a single 8.5” x 14” cheat sheet, and this quiz game below, which leverages the .CSV.

 param (
    [int]$Choices = 5
)

$ErrorActionPreference = 'stop';
$Error.Clear();

trap { if ($DebugPreference -eq 'continue') { $_.exception.message; $Host.EnterNestedPrompt(); } break; }


$scriptName = (&{$MyInvocation}).ScriptName;
$scriptDir  = Split-Path -Path $scriptName -Parent;
$csvPath =  "$scriptDir\PshIseKeyboardShortcuts.csv"

$count = ($rows = Import-Csv $csvPath).count;
$userAnswer = $null;
while ($userAnswer -notmatch '^q')
{
    $answerRow      = Get-Random -Maximum $count;
    $answerShortCut = ($rows[$answerRow]).ShortCut;
    $answerMeaning  = ($rows[$answerRow]).Meaning;

    Write-Host -ForegroundColor Green "Question:$AnswerMeaning";

    $choiceHash = @{};

    $numbersUsed = @($answerRow);
    for ($i = 1; $i -le $Choices; $i += 1)
    {
        do {
            $choiceRow = Get-Random -Maximum $count;
        } while ([array]::IndexOf($numbersUsed, $choiceRow) -ne -1)
        
        $ChoiceHash.$i = $choiceRow
    }

    $correctChoice = Get-Random -Maximum ($Choices + 1) -Minimum 1

    $ChoiceHash.$correctChoice = $answerRow

    $choiceHash.keys | sort | % {
        $choiceShortCut = ($rows[$choiceHash.$_]).Shortcut;
        Write-Host -ForegroundColor Yellow "${_}: $choiceShortCut";
    }

    $userAnswer = Read-Host -Prompt "Shortcut (number)"

    if ($userAnswer -eq $correctChoice)
    {
        Write-Host -ForegroundColor Green "CORRECT"
    }
    else
    {
        Write-Host -ForegroundColor Red "Correct answer was $correctChoice";
    }

    Write-Host ""
}

Test-PshIseKeyboardShortcuts.zip