-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).

danilo
  • 139
  • 1
  • 5
  • 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. – Matt May 24 '18 at 15:32
  • 2
    Also, I would ask the obvious question, why not write it all in powershell? – EBGreen May 24 '18 at 15:33
  • 1
    Possible duplicate of [Using command line arguments in VBscript](https://stackoverflow.com/questions/2469754/using-command-line-arguments-in-vbscript) – user692942 May 24 '18 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). – Bill_Stewart May 24 '18 at 17:19

1 Answers1

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).

Tommy
  • 74
  • 1
  • 1
  • 9