1

I have code that runs and it hits this:

$reply = Read-Host -Prompt "Continue ?[y/n]"
if ($reply -match "[yY]")

I am trying to automate it. I tried using Echo 'Y' but I get an error message that his command (the one where that chunk of code exists in) does not accept input this way.

Is there a way to pass yes to it? I cannot change the code inside the cmdlet.

noobie
  • 411
  • 1
  • 12
  • @mklement0 it doesn't. I can't start a new process. Also, the script I'm trying to run returns an object after I input 'y'. – noobie May 12 '22 at 03:20
  • See if the 2nd duplicate I've just added hellps. – mklement0 May 12 '22 at 03:28
  • @mklement0 what does that line do? ```return @{Test = 'Var1Value'; Test2 = 'Var2Value'}[$Prompt]``` Especially, the [$Prompt] at the end?! – noobie May 12 '22 at 03:50
  • It defines a hashtable whose entries are keyed by the anticipated prompt strings passed to `Read-Host` in the script and whose values are the desired automated reesponses; `[$Prompt]` is an index expression that retrieves the value of the entry whose key equals the value of `$Prompt` from the hashtable. – mklement0 May 12 '22 at 07:39

0 Answers0