1

Apologies if this question has already been answered on another thread, but I went looking for my specific query and I couldn't anything.

The issue I have is sending keystrokes to a Read-Host command. When I do this, nothing populates. Is this even possible?

$sendKeys = [System.Windows.Forms.SendKeys]
Sleep-Start -Seconds 1
$sendKeys::SendWait('serv01{ENTER}')
Read-Host -Prompt "Server Name"

Running this would only show the prompt and still waiting for input:

Server Name: 

Please advise if this is possible.

BabyPython
  • 307
  • 1
  • 2
  • 6

1 Answers1

0

Your code:

  • DOES work in regular console windows, in Windows Terminal, and - assuming the keyboard focus is on the integrated terminal when the code is run - in Visual Studio Code.

  • does NOT work in the Windows PowerShell ISE.

Note: The workaround suggested for use in the ISE may actually be the preferable solution overall, given that sending keystrokes is inherently brittle (not fully robust).

mklement0
  • 382,024
  • 64
  • 607
  • 775