在 Windows 防火墙中允许 WinRM

问题描述 投票:0回答:3

我使用的是Windows 7机器,安装了Windows Power shell。如何确保 Windows 防火墙配置为允许来自工作站的 Windows 远程管理连接。例如: netsh advfirewall 防火墙设置规则名称 =“Windows 远程管理(HTTP-In)”配置文件 = 公共协议 = tcp 本地端口 = 5985 远程 IP = 本地子网 新远程 IP = 任何

我正在执行上述命令,但无法配置它。

windows powershell winrm
3个回答
13
投票

Enable-PSRemoting -force
就是您要找的!

winrm quickconfig
也是一个很好的预防措施,启动 WinRM 服务并将该服务设置为自动启动。

但是,如果您希望对所有 Windows 7 计算机执行此操作,您可以通过 组策略

启用它

1
投票

这取决于您使用的协议。

以下一项对我有用:

Set-NetFirewallRule -Name "WINRM-HTTP-In-TCP-PUBLIC" -RemoteAddress Any

来源:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_troubleshooting?view=powershell-7.2#how-to-enable-remoting-on-public-网络


0
投票

几年前我使用它连接到远程服务器并更新 WinRM,然后将其加入域。 ($server 变量是 foreach 语句的一部分)。 我的脚本的这一部分更新 -:

  1. Windows 防火墙从公共到私有
  2. Windows 防火墙允许远程 WMI 访问
  3. 受信任的主机未加入域,因此必须添加到受信任的主机列表中
  4. 允许 RDP 的 Windows 防火墙
  5. 启用 RDP:1 = 禁用; 0 = 启用
$RequestingServer = $env:COMPUTERNAME
#Local Server Admin Account
[STRING] $LocalUser = "Administrator" #Obviously Change Account
[STRING] $LocalPassword = "Password01" #Obviously Change Password
$LocalSecurePassword = $LocalPassword | ConvertTo-SecureString -AsPlainText -Force
$LocalCredentials = New-Object System.Management.Automation.PSCredential -ArgumentList $LocalUser, $LocalSecurePassword

                #Update Windows Firewall Remotely
                $LocalSession = New-PSSession -Computername $Server -Credential $LocalCredentials
                Invoke-Command -Session $LocalSession -ScriptBlock {
                
                $AddServer = $Using:RequestingServer
                
                #Update Windows Firewall from Public to Private
                Get-NetConnectionProfile | Set-NetConnectionProfile -NetworkCategory Private
                #Update Windows Firewall to allow remote WMI Access
                netsh advfirewall firewall set rule group="Windows Management Instrumentation (WMI)" new enable=yes
                #Update Trusted Hosts is not domain-joined and therefore must be added to the TrustedHosts list 
                Set-Item wsman:\localhost\Client\TrustedHosts -Value $AddServer -Force
                #Update Windows Firewall to allow RDP
                Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
                #Enable RDP : 1 = Disable ; 0 = Enable
                Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" -Value 0
                }

© www.soinside.com 2019 - 2024. All rights reserved.