Windows PowerShell での入力の要求と受け入れ

Windows PowerShell での入力の要求と受け入れ

クイズ スクリプトで、「プログラミング初心者向け」の Seinfeld クイズ ゲームのような空欄補充の質問と回答を入力するにはどうすればよいでしょうか。

答え1

同様にRead-Host直接使用することができますSystem.Consoleクラスを使用して、1 文字を読み取ります (ENTER キーは不要)。

$key = [Console]::ReadKey()
$char = $key.KeyChar

答え2

そこにはホスト読み取りコマンドレットユーザーからの入力を読み取るために、条件付きロジック正解と照合します。

答え3

#Ask the player the seventh question
while (($question7 -eq "")) {

  Clear-Host  #Clear the Windows command console screen

  Write-Host
  Write-Host " What food item did Jerry say Newman wouldn't eat even if it was deep fried in chocolate sauce?"
  Write-Host
  Write-Host " Broccoli"
  Write-Host " Peas"
  Write-Host " Apples"
  Write-Host " Carrots"
  Write-Host
  $question7 = Read-Host " Type the word representing the correct answer" `
    "and press the Enter key"

}

関連情報