如何修复Windows错误:"WinRM服务无法改变配置.
错误的描述
This error typically occurs when you try to configure Windows Remote Management (WinRM) using commands like winrm quickconfig 或是 Enable-PSRemoting.
完整的错误信息通常是: "The WinRM service cannot make the configuration change. The configuration change is blocked because the firewall exception cannot be enabled. This can happen if the network location type for one of the network connections on this computer is set to Public."
为什么会发生
默认情况下,Windows防火墙阻止了WinRM流量 Public networks to protect your system. If even one of your active network adapters (like a virtual adapter or an unused Ethernet port) is categorized as a Public network, Windows will prevent the WinRM service from completing its setup.
简单的解决方案
您可以使用任何一个方法来解决这个问题. Windows PowerShell 或是 Windows Settings GUI.
方法1:使用PowerShell将网络配置文件更改为私有 (推)
这是最快的方法,因为它立即将您的活动网络位置从公开到私有,允许WinRM成功配置.
-
Open PowerShell as Administrator
- 按下 Start 菜单是这样的.
- 它们的类型
powershell. - 按下右键 Windows PowerShell 并且选择 Run as administrator.
-
Check your current network connection profiles
- 输入下面的命令并按下 Enter:
Get-NetConnectionProfile - 看看这个
NetworkCategory如果它说 Public, it is blocking WinRM.
- 输入下面的命令并按下 Enter:
-
Change the network category to Private
- 键入下面的命令将所有活跃配置文件更改为私有,然后按一下. Enter:
Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private - (Alternative) 如果您只想更改一个特定的网络,请使用其接口索引号码 (例如,索引4):
Set-NetConnectionProfile -InterfaceIndex 4 -NetworkCategory Private
- 键入下面的命令将所有活跃配置文件更改为私有,然后按一下. Enter:
-
Run the WinRM configuration again
- 现在网络是私有的,请再次运行设置命令:
winrm quickconfig - 或是:
Enable-PSRemoting -Force
- 现在网络是私有的,请再次运行设置命令:
方法2:通过Windows设置 (GUI) 更改网络配置文件
如果您更喜欢使用标准的 Windows 视觉界面,请按照以下步骤:
-
Open Network Settings
- 按下 Windows Key + I 在您的键盘上打开 Settings 应用程序.
- 按下 Network & internet 从左边边.
-
Select your Active Connection
- 如果您使用电缆,请点击 Ethernet.
- 如果您正在使用无线互联网,请点击 Wi-Fi 然后点击您的特定网络属性.
-
Change to Private
- 在下. Network profile type 部分, 改变选择从 Public network 为了 Private network.
-
Retry WinRM Configuration
- 打开命令行工具并重新运行
winrm quickconfig或设置命令.
- 打开命令行工具并重新运行
方法3:绕过防火墙检查 (高级选项)
如果您绝对必须将网络配置设置为 Public,但仍然需要启用 WinRM 来进行本地测试,您可以告诉 WinRM 跳过防火墙异常检查.
-
Open PowerShell as Administrator
- 右键单击开始菜单并选择 Terminal (Admin) 或是 PowerShell (Admin).
-
Run the skip-check command
- 输入下面的命令并按下 Enter:
Enable-PSRemoting -SkipNetworkProfileCheck -Force - 这会迫使WinRM在不检查或更改公共网络防火墙设置的情况下自行启用.
- 输入下面的命令并按下 Enter:
如果您遇到任何权限或群组策略障碍, 我可以提供更多命令.
可能有一些错误.. Learn Microsoft