I have a simple PowerShell script that uses both $host.ui.Prompt
and $host.ui.PromptForChoice
. When I run it from the ISE, PromptForChoice
pops up a dialog but Prompt
prompts at the console.
Read-Host also prompts at the console and does not show a dialog.
I.e. the script below shows a dialog for the initial choice, then prompts at the console pane for both A and B. Is this normal? My reading of the documentation suggests all three should throw a dialog. Have I missed something?
I'm running PowerShell 3.0 in case that's relevant.
$choicedesc = New-Object System.Collections.ObjectModel.Collection[System.Management.Automation.Host.ChoiceDescription]
$choicedesc.Add((New-Object "System.Management.Automation.Host.ChoiceDescription" -ArgumentList "&Foo"))
$choicedesc.Add((New-Object "System.Management.Automation.Host.ChoiceDescription" -ArgumentList "&Bar"))
$choice = $Host.ui.PromptForChoice("Choice", "Make a choice", $choicedesc, -1)
$a = Read-Host "A"
$fields = New-Object "System.Collections.ObjectModel.Collection[System.Management.Automation.Host.FieldDescription]"
$f = New-Object System.Management.Automation.Host.FieldDescription "B"
$f.DefaultValue = ""
$f.Label = "&B"
$fields.Add($f)
$result = $Host.ui.Prompt('cap','msg', $fields)