Windows 远程管理(WinRM)的配置确实有些让人困惑。经过一番折腾,我终于把这个功能配置成功了。下面是我的配置过程,希望对你有帮助。

服务端

启动 winrm 服务

在 PowerShell 中(以管理员身份):

net start winrm

或者在 CMD 中(以管理员身份):

winrm quickconfig

注意:如果当前用户不是原始的 "administrator" 账户,请在 CMD(以管理员身份)中运行下面的命令。

reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f

在 PowerShell 中查看 winrm 的状态:

Get-Service | findstr "WinRM"

启动监听

在 PowerShell 中启用远程管理:

Enable-PSRemoting -Force

在 CMD 中用下面的命令查看 winrm 的监听状态:

winrm enumerate winrm/config/listener

客户端

启动 winrm 服务

启动 winrm 服务(PowerShell)

net start winrm

查看服务状态(PowerShell)

Get-Service | findstr "WinRM"

启用远程管理(非必需,可跳过)

启用远程管理(PowerShell)

Enable-PSRemoting -Force

把服务器加入信任列表(必需)

把服务器 IP 加入信任列表:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.2"

Get-Item WSMan:\localhost\Client\TrustedHosts

连接服务器(如果报错,请指定计算机名)

连接服务器

Enter-PSSession x.x.x.x -Credential $X

或者

Enter-PSSession x.x.x.x -Credential yourcomputername\yourusername

注意:计算机名很重要,不指定计算机名可能会出现连接错误。

参考

https://docs.microsoft.com/en-us/windows/win32/winrm/installation-and-configuration-for-windows-remote-management

https://serverfault.com/questions/530903/enable-psremoting-on-windows-server-2008-r2-error

https://www.codeleading.com/article/2138822390/

https://www.jianshu.com/p/4361c002ac44


0 条评论

发表回复

Avatar placeholder

您的邮箱地址不会被公开。 必填项已用 * 标注