powershell内网穿透使用

内网穿透

内网穿透是在云上搭建了nps服务器,然后端口映射实现的,这里就不详细描述了

WinRM服务端

  • 运行WinRM
    Enable-PSRemoting –Force
  • 获取WinRM版本
    winrm id
    在这里插入图片描述
    3.0以上,监听端口为5985、5986
    3.0以下,监听端口为80、443

WinRM客户端

  • 运行WinRM
    Enable-PSRemoting –Force
  • 将服务器机器添加到信任列表
    Set-Item wsman:\localhost\client\trustedhosts *
    get-item wsman:\localhost\Client\TrustedHosts
  • 重启WinRM
    Restart-Service WinRM
  • 测试
    test-wsman -Port xxxx -ComputerName 10.0.0.1

常用命令

参考https://dude6.com/article/124144.html

  • PSSession
# 用户输入凭据(用户名+密码)
$cred = get-Credential
# 建立远程交互式会话
Enter-PSSession -computername 192.168.21.1 -Credential $cred
  • Invoke-Command
# 用户输入凭据(用户名+密码)
$cred = get-Credential
# 远程执行命令
invoke-command -computername 192.168.21.1 -Credential $cred -command {dir C:/}
invoke-command -computername 192.168.21.1 -Credential $cred -ScriptBlock {dir c:\}
# 远程执行脚本
echo "dir c:\" > dirDriveC.ps1
invoke-command -computername 192.168.21.1 -Credential $cred -FilePath .\dirDriveC.ps1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值