当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

作者:精品下载站 日期:2024-12-15 00:45:37 浏览:16 分类:玩电脑

如何通过 GPO 启用和配置 WinRM(Windows 远程管理)


在本文中,我们将展示如何使用组策略 (GPO) 在域计算机上启用和配置 Windows 远程管理 (WinRM)。 Windows 远程管理是 WS 管理协议的实现,用于远程管理 Windows 桌面和服务器。 WinRM 允许您通过以下方式远程管理计算机:

  • 服务器管理器(Windows 服务器)

  • PowerShell 远程处理 (PSSession)

  • Windows 管理中心 (WAC)

如何在 Windows 中手动启用 WinRM?

WinRM 服务在所有现代 Windows 版本中均可用。在 Windows Server 中,它默认启用,但在桌面 Windows 11/10/8.1 版本中禁用。默认情况下,WinRM 侦听器不接受远程连接。要检查它,请在客户端上运行以下命令:

WinRM enumerate winrm/config/listener

您将看到一条错误消息,指出 WinRM 未配置:

WSManFault Message = The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
Error number: -2144108526 0x80338012

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

要在 Windows 上启用和配置 WinRM 服务,只需运行以下命令即可:

winrm quickconfig

或者

Enable-PSRemoting -Force
WinRM has been updated to receive requests.
WinRM service type changed successfully.
WinRM service started.

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

此命令会将 WinRM 服务启动类型更改为自动,应用默认 WinRM 设置,并将 WinRM 端口(TCP 5985 和 5986)的例外添加到 Microsoft Defender 防火墙的例外列表中。

通过组策略配置 WinRM

您可以使用 Windows GPO 在域计算机上自动启用和配置 WinRM。

  1. 打开组策略管理控制台(

    gpmc.msc

    ),选择包含要启用 WinRM 的计算机的 Active Directory 容器(组织单位),然后创建一个新的 GPO:corpEnableWinRM

    [玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

  2. 打开策略进行编辑;

  3. 转到计算机配置 -> 策略 -> Windows 设置 -> 安全设置 -> 系统服务。找到Windows远程服务(WS-Management)服务并为其启用自动启动;

    [玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

  4. 然后转到计算机策略 -> 首选项 -> 控制面板设置 -> 服务。选择新建 -> 服务。输入服务名称WinRM,然后在恢复选项卡上选择重新启动服务操作;

    [玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

  5. 转到计算机配置 -> 策略 -> 管理模板 -> Windows 组件 -> Windows 远程管理 (WinRM) -> WinRM 服务。启用允许通过 WinRM 进行远程服务器管理。在 Ipv4/IPv6 筛选器框中,您可以指定必须侦听 WinRM 连接的 IP 地址或子网。如果您想允许所有 IP 地址上的 WinRM 连接,请在此处保留 *

    [玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

  6. 创建 Windows Defender 防火墙规则,允许默认端口 TCP/5985 和 TCP/5986 上的 WinRM 连接。转到计算机配置 -> 策略 -> Windows 设置 -> 安全设置 -> 高级安全 Windows 防火墙 -> 高级安全 Windows 防火墙 -> 入站规则。选择Windows远程管理预定义规则;

    [玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

    详细了解如何使用 GPO 配置 Windows Defender 规则和打开端口。

  7. 转到计算机配置 -> 策略 -> Windows 组件 -> Windows 远程 Shell 并启用允许远程 Shell 访问

    [玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

更新客户端上的 GPO 设置并确保 WinRM 已自动配置。您可以使用 gpresult 工具对客户端计算机上的组策略设置进行故障排除。

检查 WinRM 设置和 PowerShell 连接

要检查计算机上的 WinRM 设置是否是通过 GPO 配置的,请运行以下命令:

winrm e winrm/config/listener

该命令显示当前 WinRM 侦听器设置。请注意

Listener [Source="GPO"]

线。这意味着当前的 WinRM 设置是通过 GPO 配置的。

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

您可以使用 HTTPS 来保护 WinRM/PowerShell 远程连接。

您可以使用以下命令列出 WinRM 服务的完整配置:

winrm get winrm/config

然后尝试通过 WinRM 连接到远程计算机。打开 PowerShell 控制台并运行以下命令:

Test-WsMan wsk-w10b01

如果启用 WinRM,将出现以下响应:

wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor : Microsoft Corporation
ProductVersion : OS: 0.0.0 SP: 0.0 Stack: 3.0

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

您可以使用 PowerShell 检查远程计算机上是否有开放的 WinRM 端口 (TCP/5985):

Test-NetConnection -ComputerName wsk-w10b01 -Port 5985

然后,您可以尝试使用 PSRemoting 和 Enter-PSSession cmdlet 以交互方式连接到远程计算机:

Enter-PSSession wsk-w10b01

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

此时,连接成功建立,并出现远程主机的PS控制台。

除了 PSRemoting 之外,您还可以使用 Invoke-Command 在远程计算机上执行命令和脚本:

Invoke-Command -ComputerName wsk-w10b01 -ScriptBlock {ipconfig /all}

如果建立 PSRemoting 连接,您将在屏幕上看到 ipconfig 输出。

您还可以在远程主机上运行命令,如下所示:

winrs -r: wsk-w10b01 dir

在某些情况下,通过 PSSession 连接时您可能会看到以下错误:

Enter-PSSession : Connecting to remote server wsk-w10BO1 failed with the following error message : Access is denied.
CategoryInfo : InvalidArgument: (wsk-w10b01:String) [Enter-PSSession], PSRemotingTransportException FullyQualifiedErrorId : CreateRemoteRunspaceFailed

检查当前 WinRM 连接权限:

Set-PSSessionConfiguration -ShowSecurityDescriptorUI -Name Microsoft.PowerShell

确保您的帐户是管理员远程管理用户组的成员(检查如何允许非管理员用户进行 WinRm 连接)并且他们具有完全控制权限。另外,请确保没有

Deny

规则。

[玩转系统] 如何通过 GPO 启用和配置 WinRM(Windows 远程管理)

您可以根据以下指南在工作组环境(没有 Active Directory 域)中配置 WinRM 和 PSRemoting。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯