0

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
  • 2
    You forgot to post your ocde. ;-) Commented Nov 16, 2020 at 0:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.