我不是一个出色的脚本编写者,我迷失了翻译……也许我做错了……
我正在构建脚本,希望用户从选项列表中进行选择,特别是一年中的月份。然后,此结果将在脚本中稍后使用。
这是代码段:
$optionQuit = New-Object System.Management.Automation.Host.ChoiceDescription "Quit", "Quit"
$option1 = New-Object System.Management.Automation.Host.ChoiceDescription "01-January", "01-January OU"
$option2 = New-Object System.Management.Automation.Host.ChoiceDescription "02-February", "02-February OU"
$option3 = New-Object System.Management.Automation.Host.ChoiceDescription "03-March", "03-March OU"
$option4 = New-Object System.Management.Automation.Host.ChoiceDescription "04-April", "04-April OU"
$option5 = New-Object System.Management.Automation.Host.ChoiceDescription "05-May", "05-May OU"
$option6 = New-Object System.Management.Automation.Host.ChoiceDescription "06-June", "06-June OU"
$option7 = New-Object System.Management.Automation.Host.ChoiceDescription "07-July", "07-July OU"
$option8 = New-Object System.Management.Automation.Host.ChoiceDescription "08-August", "08-August OU"
$option9 = New-Object System.Management.Automation.Host.ChoiceDescription "09-September", "09-September OU"
$option10 = New-Object System.Management.Automation.Host.ChoiceDescription "10-October", "10-October OU"
$option11 = New-Object System.Management.Automation.Host.ChoiceDescription "11-November", "11-November OU"
$option12 = New-Object System.Management.Automation.Host.ChoiceDescription "12-December", "12-December OU"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($optionQuit, $option1, $option2, $option3, $option4. $option5, $option6, $option7, $option8, $option9, $option10, $option11, $option12)
$result = $host.ui.PromptForChoice($title, $message, $options, [int[]](0))
但是,我不断收到错误消息:
我不确定我缺少什么...而且我可能会使这变得比需要的复杂...但是最终变量$ result应该类似于“04-April”。
知道我在这里缺少什么吗?
最佳答案
查看您的options变量,在$ option4之后有一个句点而不是逗号。
修复该问题,它应该可以工作。
$options = [System.Management.Automation.Host.ChoiceDescription[]]($optionQuit, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $option9, $option10, $option11, $option12)