服务端
用“以管理员身份运行”的 PowerShell 执行下面几行即可:
Enable-PSRemoting -Force
Set-Service -Name WinRM -StartupType Automatic
Get-WSManInstance -ResourceURI winrm/config/listener -Enumerate
Test-WSMan localhost
建议使用一个有权限的本地账户登录,例如目标服务器名为 SERVER2025,账户为 mars.zhang;该账户至少应属于 Administrators 组。不要启用 Basic 身份验证,也不要为了图省事关闭防火墙。
下面的SID无需修改,只修改-Member后面的服务器主机名WIN-FEN5EISC9L0就行
Add-LocalGroupMember -SID 'S-1-5-32-580' -Member 'WIN-B8BCNNSIVCR\administrator'
New-ItemProperty `
-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' `
-Name LocalAccountTokenFilterPolicy `
-PropertyType DWord `
-Value 1 `
-Force
- windows查询本机公网IP
curl.exe -s https://ifconfig.me/ip
Invoke-RestMethod https://ifconfig.me/ip
irm https://ifconfig.me/ip
#绕过代理、查看直连出口
curl.exe --noproxy "*" -s https://ifconfig.me/ip
#交叉验证
curl.exe --noproxy "*" -s https://api.ipify.org
运维(客户端)
然后在你的 Win11 控制端(管理员 PowerShell)添加这台服务器为可信主机——工作组环境中用 IP 连接需要这一步:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.100"
将 IP 替换成服务器的真实局域网地址。随后测试并连接:
Test-WSMan 192.168.1.100
Enter-PSSession -ComputerName 192.168.1.100 -Credential "SERVER2025\AdminUser"
系统会提示你输入目标服务器该账户的密码。连接成功后,命令提示符会变为远程服务器上下文;输入 Exit-PSSession 可退出。
若连接失败,先在服务器运行:
Get-Service WinRM
Get-NetFirewallRule -Name WINRM-HTTP-In-TCP | Select-Object DisplayName, Enabled
确认 WinRM 是 Running,防火墙规则为启用状态。