0

How to wait for x seconds on read host in Powershell? what I'm trying to achieve xis to prompt for user input for x seconds, if the user doesn't enter the value i needed. i use the default Value.

Currently when i use read-host its waiting on user input indefinitely, i want to have a timeout on it. how can i achieve this. the code i have is below. im unable to find any option that lets me define a timer on this.

$input = Read-Host ("Enter Y or N") 
if(!input)
{
   $input = Y
}

This is regarding possible duplicate question:
In that post all answers were directed more towards whether user pressed a key or not. they did not mention how to capture the user input in there to use it?

Krishna
  • 347
  • 1
  • 6
  • 23
  • 1
    possible duplicate of [Waiting for user input with a timeout](http://stackoverflow.com/questions/150161/waiting-for-user-input-with-a-timeout) – Vesper Jun 26 '15 at 12:23
  • in that post all answers were directed more towards whether user pressed a key or not. they did not mention how to capture the user input in there to use it? – Krishna Jun 26 '15 at 12:29
  • 2
    Okay, check this [Powershell - Wait input for 10 seconds](http://stackoverflow.com/questions/16964542/powershell-wait-input-for-10-seconds) there is an answer that might suit you better, as it retrieves the value. – Vesper Jun 26 '15 at 12:32
  • Thank you, that worked. should i go ahead and delete this question? – Krishna Jun 26 '15 at 12:48

0 Answers0