用命令行把网络设为专用或公用(Set-NetConnectionProfile)
在终端里切换 Wi-Fi 或有线网络的防火墙配置文件,不用再进设置界面点来点去。
先用 Get-NetConnectionProfile 查看网卡编号,再运行 Set-NetConnectionProfile -InterfaceIndex 编号 -NetworkCategory Private。
01命令
命令
$ Get-NetConnectionProfile
Set-NetConnectionProfile -InterfaceIndex 12 -NetworkCategory Private02作用说明
专用(Private)配置文件允许文件共享和设备发现;公用(Public)配置文件会拦截外部连接,适合酒店、咖啡厅等公共 Wi-Fi。Get-NetConnectionProfile 会列出每个活动网络及其 InterfaceIndex,把这个编号传给 Set-NetConnectionProfile 即可。更改立即生效,无需重启。
03风险
!注意: 千万不要把陌生公共 Wi-Fi 设为专用——这会让同一网络里的陌生人发现并访问你的电脑。
04撤销
撤销
$ Set-NetConnectionProfile -InterfaceIndex 12 -NetworkCategory Public05来源
- Set-NetConnectionProfile依据: Documents the InterfaceIndex and NetworkCategory parameters used to move a connection between Public and Private profiles.
最后验证: 2026-09-18 · 分类: 网络
06相关方案
在 Windows 用 Test-NetConnection 测试 TCP 端口连通性
Windows 自带的 PowerShell 一行命令,直接回答“这个网络的 5432/3389/443 端口通不通”——不再需要安装 telnet 客户端。
用 Get-NetTCPConnection 列出监听端口和占用进程
netstat 的 PowerShell 原生替代品:按状态、端口、进程过滤连接,输出可直接管道处理而不用解析文本。
在 PowerShell 中用 Resolve-DnsName 查询 DNS 记录
nslookup 的现代化、可脚本化替代:查询指定记录类型、指定 DNS 服务器,并把结果当对象处理。