[英]How to request user input from the command line (at the same time that you run the script from the command line)
我有一個名為 Script.ps1 的 PowerShell 腳本。 該腳本有一個讀取主機輸入提示,但我想在運行腳本之前進行輸入。
例如:
C:\User\Desktop\Script.ps1 -輸入你好
這是請求輸入的腳本部分:
$D = 讀取主機 - 提示“在此處輸入”
您可以創建一個腳本文件,在發生參數綁定時或在命令行中提示用戶。
在命令行提示用戶:
Script.ps1 內容:
param(
[string]$in
)
"the input was $in"
運行腳本:
C:\User\Desktop\Script.ps1 -in (Read-Host "Input Here")
Output:
input here: Hello
the input was Hello
在參數綁定期間提示用戶:
Script.ps1 內容:
param(
[string]$in = (Read-Host "Input Here")
)
"the input was $in"
執行腳本:
C:\User\Desktop\Script.ps1
Output:
Input Here: hello
the input was hello
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.