gpt4 book ai didi

powershell - Powershell-让用户从一月到十二月的列表中进行选择

转载 作者:行者123 更新时间:2023-12-03 22:26:08 25 4
gpt4 key购买 nike

我不是一个出色的脚本编写者,我迷失了翻译……也许我做错了……

我正在构建脚本,希望用户从选项列表中进行选择,特别是一年中的月份。然后,此结果将在脚本中稍后使用。

这是代码段:

$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))

但是,我不断收到错误消息:

ERROR: Exception calling "PromptForChoice" with "4" argument(s): "Object reference not set to an instance of an object." TestingMenu.ps1 (31, 1): ERROR: At Line: 31 char: 1 ERROR: + $result = $host.ui.PromptForChoice($title, $message, $options, [int[] ... ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException ERROR: + FullyQualifiedErrorId : NullReferenceException ERROR:



我不确定我缺少什么...而且我可能会使这变得比需要的复杂...但是最终变量$ result应该类似于“04-April”。

知道我在这里缺少什么吗?

最佳答案

查看您的options变量,在$ option4之后有一个句点而不是逗号。

修复该问题,它应该可以工作。

$options = [System.Management.Automation.Host.ChoiceDescription[]]($optionQuit, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $option9, $option10, $option11, $option12)

关于powershell - Powershell-让用户从一月到十二月的列表中进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40642351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com