PoshCode Archive  Artifact [3ed8a7377e]

Artifact 3ed8a7377e9bae2ded30bfef0907e293c067bddb9fbed066b85e75e57455df7b:

  • File Using-Read-Choice.ps1 — part of check-in [a24a5753e4] at 2018-06-10 14:05:53 on branch trunk — I saved Joel Bennett’s Read-Choice function as a module and wrote this function. I wanted to make it useful (especially to beginners) so it doesn’t look like a “normal” menu script, but Bennett’s function is so friendly that you could write a “normal” menu script without using variables at all. To create the module save Read-Choice in a file named ReadChoice.psm1 and save it in $PSModulePath\ReadChoice. (user: Vince Ypma size: 1949)

# encoding: ascii
# api: powershell
# title: Using Read-Choice
# description: I saved Joel Bennett’s Read-Choice function as a module and wrote this function.  I wanted to make it useful (especially to beginners) so it doesn’t look like a “normal” menu script, but Bennett’s function is so friendly that you could write a “normal” menu script without using variables at all.  To create the module save Read-Choice in a file named ReadChoice.psm1 and save it in $PSModulePath\ReadChoice.
# version: 0.1
# type: function
# author: Vince Ypma
# license: CC0
# function: Invoke-PowerTipsMenu
# x-poshcode-id: 6001
# x-archived: 2016-05-17T10:50:41
# x-published: 2016-09-04T01:21:00
#
#
function Invoke-PowerTipsMenu
{
    function Start-PowerTipsMonthly ([int]$Volume)
    {
        [string]$urlHead = "http://powershell.com/cs/media/p"
        [string]$urlTail = "download.aspx"
        [int[]]$urlIndex = @(0, 23856, 24814, 25742, 26784, 28283, 29098,
                                29920, 30542, 31297, 32274, 33169, 38383)

        Start-Process -FilePath "$urlHead/$($urlIndex[$Volume])/$urlTail"
    }

    Import-Module -Name ReadChoice

    [string]$title  = "`nPowerTips Monthly`n" + ("="*17)
    [string]$prompt = "`nSelect PowerTips Monthly Volume(s)`n" + ("-"*34)

    "&File System Tasks",
    "&Arrays and Hash Tables",
    "&Date, Time, and Culture",
    "&Objects and Types",
    "&WMI",
    "Regular &Expressions",
    "F&unctions",
    "Static .&NET Methods",
    "&Registry",
    "&Internet-Related Tasks",
    "&XML-Related Tasks",
    "&Security-Related Tasks",
    "&Quit" | 
        Read-Choice -Title $title -Prompt $prompt -MultipleChoice |
            ForEach-Object {
                if (0..11 -contains $_)
                {
                    Start-PowerTipsMonthly -Volume ($_ + 1)
                }
            }

    Remove-Module -Name ReadChoice
}