powershell - 标签无法识别
问题描述
我对 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
对于我正在使用的每个排列,我都会收到相同的错误“术语....”。我觉得我错过了一些简单的东西。
解决方案
推荐阅读
- ruby - 通过 Ruby git gem 读取存储库源代码文件?
- elasticsearch - 如何使用elasticsearch地理查询获取距离大于x公里的文档
- ionic-framework - 离子水平重新排序列表
- batch-file - 如何在批处理脚本中正确执行与字符串的数字比较
- django - 以多对多关系显示来自中间表的数据
- jquery - Angular JS 中的美化 URL 部分工作
- java - 来自php的带有base64字符串的java合法base64字符20
- c# - 单元测试用例 - 从查询字符串参数中传递和获取值
- javascript - 数据表未正确排序
- mysql - SQL - 根据日期+循环显示不同的工作日通过相应的记录