内网穿透
内网穿透是在云上搭建了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