Powershell Session

服务器上WinRM服务默认是开启的,

查看服务是否开启,服务监听5985

Get-Service winrm*

如果没有开启,使用一下指令开启。

Enable-PSRemoting -Force

在用户端连接服务器,

-Credential 可以使用域账号或本地的administrator,其他本地账号要添加到Remote Management Users组里才能连接。

New-PSSession -ComputerName 主机名或IP   -Credential "domain\user"

报错

连接到远程服务器失败,错误消息如下: WinRM 客户端无法处理该请求。如果身份验证方案与 Kerberos 不同,或者
客户端计算机未加入到域中, 则必须使用 HTTPS 传输或者必须将目标计算机添加到 TrustedHosts 配置设置。 使用 winrm.cmd 配置
TrustedHosts。请注意,TrustedHosts 列表中的计算机可能未经过身份验证。 通过运行以下命令可获得有关此内容的更多信息: winrm
help config。 有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。
+ CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken

先启动客户端的winrm,然后将服务器IP添加到客户端的信任列表,重新建立会话即可。

Start-Service winrm
 Set-Item wsman:\localhost\client\trustedhosts *

查看本地建立的会话

Get-PSSession

进入会话,根据会话ID

Enter-PSSession 3
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PowerShell中,你可以使用OpenSSH模块来登录到SSH服务器。以下是一个示例: 1. 首先,确保你的计算机已安装OpenSSH模块。你可以在PowerShell中运行以下命令来检查: ``` Get-Module -ListAvailable OpenSSH* ``` 如果没有安装OpenSSH模块,你可以使用以下命令来安装它: ``` Install-Module -Name OpenSSH.Client -Force ``` 2. 安装完毕后,你可以使用以下命令来登录到SSH服务器: ``` $username = 'your_username' $password = 'your_password' $hostname = 'ssh_server_hostname' $session = New-SSHSession -ComputerName $hostname -Credential (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, (ConvertTo-SecureString -AsPlainText $password -Force)) ``` 请注意替换`your_username`、`your_password`和`ssh_server_hostname`为相应的值。 3. 成功登录后,你可以执行命令或操作远程服务器。以下是一些示例: - 执行命令并获取输出: ``` Invoke-SSHCommand -SessionId $session.SessionId -Command 'your_command' ``` - 上传文件到SSH服务器: ``` Set-SCPFile -SessionId $session.SessionId -LocalFile 'local_file_path' -RemotePath 'remote_file_path' ``` - 下载文件从SSH服务器: ``` Get-SCPFile -SessionId $session.SessionId -RemotePath 'remote_file_path' -LocalFile 'local_file_path' ``` - 关闭SSH会话: ``` Remove-SSHSession -SessionId $session.SessionId ``` 这是一个基本的示例,你可以根据需要进行调整和扩展。注意,登录SSH服务器需要提供正确的用户名、密码和主机名。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值