-4

I try to create a script for automatically connect to SSH. I have a variables with all parameters of SSH (username, password, port, ip).

If I launch, in a VBS script:

Set objShell = CreateObject("Wscript.shell")
objShell.run("powershell -noexit ssh.exe " & user & "@" & ip & " -p " & port & "")

the powershell opens correctly and ask me a password of server...but

How can I send the password in VBS script? I have variable "pass" with the password of server (SSH).

Please Help me I have try a lot of solutions but it's doesn't works.

I have try with:

objShell.run("powershell -noexit & ssh.exe " & user & "@" & ip & " -p " & porta & "; " & pass &"")

objShell.run("powershell -noexit ssh.exe " & user & "@" & ip & " -p " & porta & " + " & pass &"")

with ";" the script passed the password but it doesn't send it when ssh ask me a password.

Also, I would ask the obvious question, why not write it all in powershell?

I already have a script in VBS and I want to change only the line of connection (now works fine with cygwin).

Why run it from PowerShell at all? Just run ssh.exe directly. Or even easier, just run the ssh command directly from the PowerShell prompt (PowerShell is a shell; it can run commands you type - that's one of the reasons it exists).

I must launch powershell from a script and send the password of SSH automatically (I don't want to type the password manually).

4
  • It would be helpful for everyone if you added some of the things you tried that did not work. If nothing else, so people don't waste their time asking you about those approaches. Commented May 24, 2018 at 15:32
  • 2
    Also, I would ask the obvious question, why not write it all in powershell? Commented May 24, 2018 at 15:33
  • 1
    Possible duplicate of Using command line arguments in VBscript Commented May 24, 2018 at 16:38
  • 1
    Why run it from PowerShell at all? Just run ssh.exe directly. Or even easier, just run the ssh command directly from the PowerShell prompt (PowerShell is a shell; it can run commands you type - that's one of the reasons it exists). Commented May 24, 2018 at 17:19

1 Answer 1

0

What about executing a Powershell script?

param([String]$Pass,[String]$User)
$ErrorActionPreference = "Continue"

$secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)

Now you can use the $credential variable to connect to SSH (I dont know how, I never tried SSH from Powershell).

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.