我的第一步是创建2个变量并将其值设置为args[0]
和args[1]
,然后使用if
语句包含一些错误检查Write-Warning
和{ {1}}捕获用户输入并将值存储在变量中。
这是我的代码:
Read-Host
问题是:
写下这样的if语句:
# Create 2 command line variables $workingdirectory = ARGS[0] $directoryname = ARGS[1] ## Check if variables are empty and get user input if necessary if ("$workingdirecytory" -eq "") { Write-Warning "Parameter Required" $workingdirectory = Read-Host "Enter absolute path to working directory" Write-Warning "Parameter Required" $directoryname = Read-Host "Enter directory name to search for in $workingdirectory" } Write-Host "$workingdirectory" Write-Host "$directoryname"
在脚本块中添加以下内容:
- 使用
If (“$WorkingDirectory” –eq “”) {
cmdlet显示消息“Parameter Required”- 使用
中Write-Warning
捕获用户输入并将值存储在变量Read-host
- 对DirectoryName重复
我是否想要为目录名称添加另一个$WorkingDirectory
语句?
尝试使输出看起来像这样:
by: