Windows Terminal + PowerShell 7:干净、可重复的配置
并排安装 Windows Terminal 与 PowerShell 7,设置默认配置、字体和 settings.json,不运行看不懂的 profile 脚本。
- 版本号
- 26300.9457
- 版本
- Pro (26H2)
- 架构
- x64
- 支持
- 文档(E1)
- 证据
- E1官方文档
- 核验日期
- 2026-10-28
- 页面类型
- 配置
装 Windows Terminal 管窗口,装 PowerShell 7 管 shell。它们是两个产品,可以和 Windows PowerShell 5.1 共存。
用一个小 settings.json,把 PowerShell 7 设为默认配置,选可读的等宽字体,profile 脚本尽量少。终端配置不是安全边界;不要运行从随机 gist 复制的 profile。
winget install --id Microsoft.WindowsTerminal -ewinget install --id Microsoft.PowerShell -e或用 Microsoft Store/MSI。装完:
pwsh -NoLogo$PSVersionTablepwsh.exe 是 PowerShell 7;powershell.exe 是 Windows PowerShell 5.1。两个都留:一些老模块只在 5.1 工作。
Windows Terminal → 设置 → 启动 → 默认配置文件 → PowerShell 7。也可以在 Windows 设置 → 系统 → 开发者选项里设默认终端应用。
配置是自动生成的;不需要自定义配置时,不要手改生成的 GUID 块。不熟 JSON 就用设置 UI 改字体和颜色。
最小 settings.json
Section titled “最小 settings.json”Store 版路径:%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json。最小改动:
{ "defaultProfile": "{GUID-of-PowerShell-7}", "profiles": { "defaults": { "font": { "face": "Cascadia Mono", "size": 11 }, "opacity": 95 } }}不要删生成的 profiles 或 schemes 数组。改前备份;JSON 格式坏了 Terminal 可能起不来。
Profile 脚本
Section titled “Profile 脚本”PowerShell profile 每次开 shell 都运行。保持小且可审计:
$PROFILE.CurrentUserAllHostsTest-Path $PROFILE.CurrentUserAllHosts用提示主题/模块就从已知来源装,并固定版本。启动时下载并执行代码的 profile 是供应链风险。
不要机器级设 Unrestricted 或 Bypass。优先:
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned经常运行的自己的脚本要签名。执行策略不是安全沙箱,是护栏。
- 默认 PowerShell 7;保留 Windows PowerShell 5.1 给老模块。
- Cascadia Mono 或其他可读等宽字体;不要 8pt。
- profile 最小化;启动不联网。
- PATH 里有
winget和 Git。 - Terminal 固定到任务栏;用
wt启动。