Reputation: 381
I am currently adding a Parameter to a script. The outcome I want is that if the script is run manually - that the user will get prompted like this for an input:
Press 1 for Option blah
Press 2 for Option bleh
Press 3 for Option blih
Press 4 for Option bloh
I've used an options array before:
$optionsarray = @()
$optionsarray += $Zero
foreach($_ in $variablearray){
$word = Convert-NumbertoWords $_
$tmp2 = (get-variable -name $_).value
$tmp = Write-Output $word[1].trim()
$tmp3 = New-Object System.Management.Automation.Host.ChoiceDescription "$tmp", "$tmp2"
New-Variable -Name $tmp -Value $tmp3
$optionsarray += $tmp3
}
#Combine the options array to an actual options object
$options = [System.Management.Automation.Host.ChoiceDescription[]]($optionsarray)
#prompt the user for the choice
$title = 'Select the Option'
$message = 'Hover over each option to check what the description is'
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
}
(this bit of code looped through multiple lines of an output, assigned a number to each one, so that the end-user could input a number to select the option)
I want to do something similar but with a Parameter. So they get prompted if they run it normally, or once they are familiar with it then can call it from the CLI e.g.
.\myscript.ps1 -option 1
But I'm not sure if this is possible to do in a mandatory parameter?
Upvotes: 1
Views: 79