I have the challenge to automate a ssh login to a Linux box which asks after login th accept a eula. So I need to press two time the arrow down key and after this the a key and a enter. Is there a way to do this with power shell?
1 Answer
You can do this with SendKeys.
Start the process that way we can find the window easier. Otherwise, just change the console title and search for that instead.
Start-Process ssh Server-Name
Sleep 1
To send keys to a window you need to activate that window "C:\Windows\System32\OpenSSH\ssh.exe" was the title of my window once I did a Start-Process
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('C:\Windows\System32\OpenSSH\ssh.exe')
Then your config.
Sleep 1
$wshell.SendKeys('{DOWN}')
Sleep 1
$wshell.SendKeys('{DOWN}')
Sleep 1
$wshell.SendKeys('a')
Login
$wshell.SendKeys('mysupersecurepasswordnobodywilleverguess')
$wshell.SendKeys('{ENTER}')
I will suggest you encrypt your password before using it in a script like this.