查看并修改 Windows 的网络配置文件(公用/专用)

用 Get-NetConnectionProfile 查看每个连接所属的防火墙类别,再用 Set-NetConnectionProfile 修改。

Windows网络PowerShell防火墙低风险
运行 Get-NetConnectionProfile 查看每个连接的 NetworkCategory,用 Set-NetConnectionProfile -InterfaceIndex N -NetworkCategory Private 修改。

01命令

命令
$ Get-NetConnectionProfile | Format-Table Name,InterfaceAlias,NetworkCategory -AutoSize

02作用说明

这就是“是否希望你的电脑可被发现?”提示背后的 cmdlet,而 Windows 会把新网络静默设为“公用”,从而静默阻止入站连接和文件共享。Get 用于查看这个常被遗忘的状态,Set-NetConnectionProfile 则按接口修改。由于防火墙规则按配置文件限定作用范围,只对“专用”创建的规则在网卡仍是“公用”时永远不会生效——这是典型的隐形故障。

03风险

风险低风险
!注意: 把陌生网络标记为“专用”会启用网络发现并放宽防火墙规则——只对你可控的网络这样做。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Get-NetConnectionProfile | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents Get-NetConnectionProfile as retrieving connection profile data including NetworkCategory (Public, Private, DomainAuthenticated).

最后验证: 2026-09-17 · 分类: 网络

06相关方案