0
votes

Windows offers a ssh client. In Powershell I can connect with ssh user @ server.

How can I use the client in a script while passing credentials?

There are examples on the net about New-PSsession:

$ session = New-PSSession -HostName WinVM2 -UserName PSRemoteUser

Powershell Version 5.1 / New Pssession does not know the parameters hostname and username.

The following have no Error but the script hangs:

  $ session = New-PSSession -SSHTransport -ComputerName 192.168.2.50 -Credential root

If you use ssh user @ server directly in the script you will not be asked to enter a password.

Other modules should not be installed.

Does one have an idea?

2
Is this about ssh or pssession? Type: help New-PSSession -detailed ...for the current parameters and how to use them.Scepticalist

2 Answers

0
votes

The -Credential parameter for New-PSSession isn't a string, it's a PSCredential object that you will need to create. MS gives a pretty good example on how to do so.

https://blogs.msdn.microsoft.com/koteshb/2010/02/12/powershell-how-to-create-a-pscredential-object/

0
votes

If you want to use ssh and scp in your script without dealing with password you should install your public ssh key on you server. Create a ssh key pair with ssh-keygen And copy your public key on the server in the file: C:\Users\ServerUser\.ssh\authorized_keys if it's a Windows Server