gpt4 book ai didi

windows - Powershell 脚本 : SSH into Server

转载 作者:可可西里 更新时间:2023-11-01 10:41:34 25 4
gpt4 key购买 nike

我想知道是否可以编写一个 powershell 脚本,通过 ssh 连接到服务器,然后在该服务器上执行某些操作。

感谢您的帮助。

最佳答案

网络上有很多关于这个主题的文章,而且由于 PowerShell Core 现在是开源的并且可以安装在 Windows/Linux/OSX 上,因此 PowerShell 的 SSH 已经存在了一段时间。

示例:

Using SSH to Access Linux Servers in PowerShell

Using SSH with PowerShell

Managing Windows Powershell from Linux terminal

MS PowerShellGallery 上有几个模块专门用于此用例。

Find-Module -Name '*ssh*'

Version Name Repository Description
------- ---- ---------- -----------
2.0.2 Posh-SSH PSGallery Provide SSH and SCP functionality for executing commands against remote hosts.
2.1.3 SSHSessions PSGallery Svendsen Tech's SSH-Sessions module provides SSH session creation, management and interact...
0.0.2.0 OpenSSHUtils PSGallery Utilities and functions for configuring OpenSSH on Windows.
1.0.0 SSH PSGallery Provides a PowerShell-based SSH client based on SSH.net http://sshnet.codeplex.com/
1.1.3 PowerSSH PSGallery This module detects the first use of an SSH command, automatically runs the SSH agent, kee...
0.9.4 WinSSH PSGallery Install OpenSSH-Win64, optionally install ssh-agent and sshd Services. Also includes funct...
0.0.30 PSSharedGoods PSGallery Module covering functions that are shared within multiple projects
1.0.1 ssh-wrapper PSGallery Exposes ssh from WSL by wrapping: bash -c "ssh $args". Requires Windows Subsystem for Linu...
1.0.4 PSShortcut PSGallery This module eases working with Windows shortcuts (LNK and URL) files.
1.0 cEPRSSharepoint PSGallery DSCModule helps in installing & configuring the sharepoint site, Farm etc.,
2.0.1.8 SkypeForBusinessHybridHealth PSGallery Uses on-premises modules such as Skype For Business and SkypeOnlineConnector to validate b...
0.3.1 posh-sshell PSGallery Provides integration with ssh-agent and pageant from within Powershell
1.1.4 PowerSSH-Legacy PSGallery This module detects the first use of an SSH command, automatically runs the SSH agent, kee...

SSH From Windows Server to Linux Server - Invoke-SSHCommand

Invoke-SSHCommand $IndexID.SessionID -command "curl -v telnet://WindowsServerA:4750& sleep 2; kill $!"

# Results

Host : LinuxServerA
Output : {}
ExitStatus : 0



Invoke-SSHCommand $IndexID.SessionID -command "curl -v telnet://LinuxServerB:4750& sleep 2; kill $!"

# Results
Host : LinuxServerA
Output : {}
ExitStatus : 0



Invoke-SSHCommand $IndexID.SessionID -command "curl -v telnet://WindowsServerA:4750 2>&1 & sleep 2; kill $!"

# Results
Host : LinuxServerA
Output : {* About to connect() to WindowsServerA port 4750, * Trying 10.10.10.10... connected, * Connected to
WindowsServerA (10.10.10.10) port 4750}
ExitStatus : 0



Invoke-SSHCommand $IndexID.SessionID -command "curl -v telnet://LinuxServerB:4750 2>&1 & sleep 2; kill $!"

# Results
Host : LinuxServerA
Output : {* About to connect() to LinuxServerB port 4750, * Trying 10.10.10.11... connected, * Connected to
LinuxServerB (10.10.10.11) port 4750}
ExitStatus : 0

关于windows - Powershell 脚本 : SSH into Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53034988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com