powershell - Connect to ssh server with powershell
问题描述
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?
解决方案
New-PSSession 的 -Credential 参数不是字符串,而是您需要创建的 PSCredential 对象。MS给出了一个很好的例子来说明如何做到这一点。
https://blogs.msdn.microsoft.com/koteshb/2010/02/12/powershell-how-to-create-a-pscredential-object/
推荐阅读
- wordpress - 条纹信用卡字段不适用于 WordPress
- ibm-cloud-private - IBM Cloud Private ICP 禁用 ldap
- c# - 如何让代码每天运行一次并被阻止到凌晨 1 点
- java - 将保存点添加到数据流
- r - str_sub 使用 ifelse 返回 NA
- angular - Angular Observables
- java - 防止 Common Navigator Framework 中的树标签和图像重叠
- javascript - 如何在打字稿中获得“this”的范围
- spring - Spring MVC 圆形视图路径
- c# - UWP 等待 Textbox.Textchanged 事件触发