Windows 命令速查
用 winget 装机
Section titled “用 winget 装机”Windows 11 自带 winget,不需要额外装包管理器。先搜索确认包 ID,再按 ID 安装,避免装错同名软件。
winget search "Visual Studio Code"winget install --id Microsoft.PowerShell --source wingetwinget install --id Git.Git --source winget批量装机把 ID 列成清单,一次跑完:
'Microsoft.PowerShell', 'Git.Git', 'Microsoft.VisualStudioCode' | ForEach-Object { winget install --id $_ --source winget --accept-package-agreements }升级已安装的软件
Section titled “升级已安装的软件”# List what has updates availablewinget upgrade
# Upgrade everything at oncewinget upgrade --all --include-unknownPowerShell 执行策略
Section titled “PowerShell 执行策略”默认策略会拦下本地脚本。按当前用户放开即可,不要动系统级策略。
Get-ExecutionPolicy -ListSet-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned网络与端口排查
Section titled “网络与端口排查”# Which process holds port 4321Get-NetTCPConnection -LocalPort 4321 -State Listen | Select-Object OwningProcessGet-Process -Id <PID>
# Flush the DNS cacheClear-DnsClientCache
# Trace the route to a hostTest-NetConnection 1.1.1.1 -TraceRoute连上 Wi-Fi 却上不了网
Section titled “连上 Wi-Fi 却上不了网”典型症状:能连上 Wi-Fi,但什么都打不开;同一个网络下别人正常;这台机器换个网络也正常。这说明网卡和路由器本身都没坏,问题出在「这台机器 × 这个网络」这一对组合上。
有网的时候(比如手机热点)直接跑脚本,它会从网卡往上逐层探测,指出第一个断掉的层:
irm https://hub.skillnav.dev/net.ps1 | iex
# Same run, plus the two safe repairs: flush DNS, renew an existing DHCP lease$env:HUB_FIX = '1'; irm https://hub.skillnav.dev/net.ps1 | iex脚本下载不下来的时候(网全断了就是这种情况),手敲下面四条,按同样的顺序判断:
# 1. Address and how it was obtained. PrefixOrigin "Manual" means a static IP# someone typed in; 169.254.x.x means DHCP never answered.Get-NetIPAddress -AddressFamily IPv4 | Format-Table InterfaceAlias, IPAddress, PrefixOrigin
# 2. Can the router be reached at allGet-NetRoute -DestinationPrefix '0.0.0.0/0' | Format-Table InterfaceAlias, NextHopping <上一行看到的 NextHop>
# 3. Public IP, bypassing DNS entirelyping 223.5.5.5
# 4. Name resolutionResolve-DnsName www.apple.com怎么读这四条:
| 卡在哪 | 结论 |
|---|---|
拿不到地址,或是 169.254.x.x |
DHCP 没应答。先 ipconfig /renew;仍是这个地址就是路由器侧拦了这台机器 |
PrefixOrigin 是 Manual,且网关 ping 不通 |
静态 IP 是别的网络留下的残留,改回自动即可 |
| 网关 ping 不通 | 路由器按 MAC 过滤。随机硬件地址开着时,这台机器每次都像陌生设备 |
网关通、223.5.5.5 不通 |
Portal 认证没过,或这台设备被上游拦了 |
223.5.5.5 通、域名解析失败 |
DNS 问题,多半是手工填过别处的 DNS 服务器 |
| 全通但浏览器打不开 | 代理残留,查 Internet 选项和 netsh winhttp show proxy |
setx 写入的是持久化环境变量,当前窗口不会立即生效,需要新开一个终端。
# Persist for the current usersetx EDITOR "code --wait"
# Read it back[Environment]::GetEnvironmentVariable('EDITOR', 'User')完整流程见 Windows 11 重装手册,这里只收单行命令。
# Read the OEM product key embedded in the firmware (empty on most custom builds)(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
# Verify an ISO before writing it to a USB drivecertutil -hashfile Win11.iso SHA256| 用途 | 命令 / 位置 |
|---|---|
| 开箱设置里呼出命令行 | Shift + F10 |
| 断网后跳过联网(部分版本仍有效) | oobe\bypassnro |
| 建本地账户(预览版已封,正式版不一定可用) | start ms-cxh:localonly |
| 绕过硬件检测(官方安装程序) | HKLM\SYSTEM\Setup\LabConfig 下建 BypassTPMCheck / BypassSecureBootCheck / BypassRAMCheck,值为 1 |
| 查 BIOS 模式 | msinfo32 → BIOS 模式 |
| 核对 U 盘磁盘编号 | diskmgmt.msc |
| 镜像路径 | <光驱盘符>:\sources\install.esd |
| 双系统:GRUB 找回 Windows | sudo os-prober && sudo update-grub(在 Ubuntu 里执行) |
| 双系统:修时间差 8 小时 | timedatectl set-local-rtc 1(在 Ubuntu 里执行) |