用命令行把网络设为专用或公用(Set-NetConnectionProfile)

在终端里切换 Wi-Fi 或有线网络的防火墙配置文件,不用再进设置界面点来点去。

Windows配置网络PowerShell低风险
先用 Get-NetConnectionProfile 查看网卡编号,再运行 Set-NetConnectionProfile -InterfaceIndex 编号 -NetworkCategory Private。

01命令

命令
$ Get-NetConnectionProfile
Set-NetConnectionProfile -InterfaceIndex 12 -NetworkCategory Private

02作用说明

专用(Private)配置文件允许文件共享和设备发现;公用(Public)配置文件会拦截外部连接,适合酒店、咖啡厅等公共 Wi-Fi。Get-NetConnectionProfile 会列出每个活动网络及其 InterfaceIndex,把这个编号传给 Set-NetConnectionProfile 即可。更改立即生效,无需重启。

03风险

风险低风险
!注意: 千万不要把陌生公共 Wi-Fi 设为专用——这会让同一网络里的陌生人发现并访问你的电脑。

04撤销

撤销
$ Set-NetConnectionProfile -InterfaceIndex 12 -NetworkCategory Public

05来源

  • Set-NetConnectionProfile
    Microsoft Learn · vendor-doc · 2026-09-17
    依据: Documents the InterfaceIndex and NetworkCategory parameters used to move a connection between Public and Private profiles.

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

06相关方案