ShellMenuX.psm1

function Show-ShellMenu {
    param(
        [Parameter(Mandatory=$true)]
        [string]$Header,
        [Parameter(Mandatory=$true)]
        [array]$MenuOptions,
        [Parameter(Mandatory=$false)]
        [System.ConsoleColor]$SelectionEmphasisColor = 'green'
    )

    $MaxValue = $MenuOptions.Count-1
    $Selection = 0
    $EnterKeyPressed = $false

    Clear-Host

    While ($EnterKeyPressed -eq $false){
        Write-Output "$Header"

        for ($i=0; $i -le $MaxValue; $i++){
            if ($i -eq $Selection){
                Write-Host ">[ $($MenuOptions[$i]) ]" -ForegroundColor $SelectionEmphasisColor 
            } else {
                Write-Host "| $($MenuOptions[$i]) "
            }
        }

        $InputKey = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").VirtualKeyCode

        switch($InputKey){
            13{
                $EnterKeyPressed = $true
                Return $Selection
                Clear-Host
                Break
            }

            38{
                if ($Selection -eq 0){
                    $Selection = $MaxValue
                } else {
                    $Selection -= 1
                }
                
                Clear-Host
                Break
            }

            40{
                if ($Selection -eq $MaxValue){
                    $Selection = 0
                } else {
                    $Selection += 1
                }
                
                Clear-Host
                Break
            }

            Default{
                Clear-Host
            }
        }
    }
}


Set-Alias shellmenu Show-ShellMenu
Set-Alias shmenu Show-ShellMenu

Export-ModuleMember -Function Show-ShellMenu
Export-ModuleMember -Alias shellmenu
Export-ModuleMember -Alias shmenu