我有该脚本,该脚本可以正常工作,并且可能缺少一些愚蠢的迹象,但我只是找不到它。
请帮帮我?
应该弹出一个选择栏并根据所选项目更改$ answer。

#What project do you work on
$caption = "Choose Action";
$message = "What project are you testing?";
$LLL = new-Object System.Management.Automation.Host.ChoiceDescription "&LLL","LLL";
$JJJ = new-Object System.Management.Automation.Host.ChoiceDescription "&JJJ","JJJ";
$PPP = new-Object System.Management.Automation.Host.ChoiceDescription "&PPP","PPP";
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($LLL,$JJJ,$PPP);
$Project = $host.ui.PromptForChoice($caption,$message,$choices,0)

switch ($Project) {
    0 {"LLL"; break}
    1 {"JJJ"; break}
    2 {"PPP"; break}
    }


if ($Project -eq 0)
    {
    $Answer = "LLL"
    }


if ($Project -eq 1)
    {
    $Answer = "JJJ"
    }


if ($Project -eq 2)
    {
    $Answer = "PPP"
    }


the error is that

o.ps1:128 char:23
+     if ($Project -eq 1)
+                       ~
Missing statement block after if ( condition ).
At ps1:136 char:27
+         if ($Project -eq 2)
+                           ~
Missing statement block after if ( condition ).
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingStatementBlock

最佳答案

您的代码应该可以工作。如果只想设置$Answer,也可以在您的switch块中进行设置:

$Answer = switch ($Project) {
    0 {'LLL'}
    1 {'JJJ'}
    2 {'PPP'}
}

现在您可以省略所有if语句...

07-24 09:39
查看更多