标签无法识别

时间:2019-07-02 19:55:47

标签: powershell label

我对Power Shell有点陌生。我正在编写脚本以自动化PC生成过程。该过程的总体设计是,最终运行的程序在最初运行时会询问用户一些数据,然后将该数据存储在注册表中以供以后检索,然后执行其任务。它重命名计算机,将其加入域,然后执行其他一些基本设置。由于重命名和加入域需要重新启动,所以我在程序运行时读取的注册表中使用状态值。我根据阶段使用switch跳到脚本中的适当标签。我还在验证用户输入的地方使用标签。这是我遇到的问题-标签引发错误。

我查看了许多有关标签的站点,并根据所看到的内容,使它们正确无误-除非我误解了某些东西(这总是可能的)。我已完成以下操作:

:Label
<code goes here>

:Label
    {
    <code goes here>
    }

:Label <code goes here>

所有行为都相同。

这是使用标签并引发错误的代码示例(此后甚至不执行更高的部分)。这是用户输入部分的一部分。

# User Input
:UserInput Write-Output "Please provide the following information in order to properly image the system:"

    :Country $Country=Read-Host "Enter 2 character destination country code"
        IF(!$Country)
            {
            Write-Output "The destination country is required!"
            Break :Country
            }

这段代码会产生以下错误:

:UserInput : The term ':UserInput' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At <sanitized for my protection>Kiosk_PC_Build_V0_1a.ps1:79 char:1
+ :UserInput Write-Output "Please provide the following information in  ...
+ ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:UserInput:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


:Country : The term ':Country' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if 
a path was included, verify that the path is correct and try again.
At <sanitized for my protection>Kiosk_PC_Build_V0_1a.ps1:81 char:5
+     :Country $Country=Read-Host "Enter 2 character destination countr ...
+     ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:Country:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

对于我正在使用的每个排列,我都会得到相同的错误“ The term ....”。我感觉自己缺少一些简单的东西。

0 个答案:

没有答案