# Windows Terminal + PowerShell 7：干净、可重复的配置

> 并排安装 Windows Terminal 与 PowerShell 7，设置默认配置、字体和 settings.json，不运行看不懂的 profile 脚本。

**测试环境**

- 版本号: 26300.9457
- 版本: Pro (26H2)
- 架构: x64
- 证据: E1
- 核验日期: 2026-10-28

## 一句话结论

装 **Windows Terminal** 管窗口，装 **PowerShell 7** 管 shell。它们是两个产品，可以和 Windows PowerShell 5.1 共存。

用一个小 `settings.json`，把 PowerShell 7 设为默认配置，选可读的等宽字体，profile 脚本尽量少。终端配置不是安全边界；不要运行从随机 gist 复制的 profile。

## 安装

```powershell
winget install --id Microsoft.WindowsTerminal -e
winget install --id Microsoft.PowerShell -e
```

或用 Microsoft Store/MSI。装完：

```powershell
pwsh -NoLogo
$PSVersionTable
```

`pwsh.exe` 是 PowerShell 7；`powershell.exe` 是 Windows PowerShell 5.1。两个都留：一些老模块只在 5.1 工作。

## 设默认配置

Windows Terminal → **设置 → 启动 → 默认配置文件 → PowerShell 7**。也可以在 Windows 设置 → 系统 → 开发者选项里设默认终端应用。

配置是自动生成的；不需要自定义配置时，不要手改生成的 GUID 块。不熟 JSON 就用设置 UI 改字体和颜色。

## 最小 settings.json

Store 版路径：`%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json`。最小改动：

```json
{
  "defaultProfile": "{GUID-of-PowerShell-7}",
  "profiles": {
    "defaults": {
      "font": { "face": "Cascadia Mono", "size": 11 },
      "opacity": 95
    }
  }
}
```

不要删生成的 profiles 或 `schemes` 数组。改前备份；JSON 格式坏了 Terminal 可能起不来。

## Profile 脚本

PowerShell profile 每次开 shell 都运行。保持小且可审计：

```powershell
$PROFILE.CurrentUserAllHosts
Test-Path $PROFILE.CurrentUserAllHosts
```

用提示主题/模块就从已知来源装，并固定版本。启动时下载并执行代码的 profile 是供应链风险。

## 执行策略

不要机器级设 `Unrestricted` 或 `Bypass`。优先：

```powershell
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
```

经常运行的自己的脚本要签名。执行策略不是安全沙箱，是护栏。

## 合理基线

- 默认 PowerShell 7；保留 Windows PowerShell 5.1 给老模块。
- Cascadia Mono 或其他可读等宽字体；不要 8pt。
- profile 最小化；启动不联网。
- PATH 里有 `winget` 和 Git。
- Terminal 固定到任务栏；用 `wt` 启动。

> **警告: 不要粘贴未知 profile 代码**
>
> PowerShell profile 每次开 shell 都以你的权限运行。复制的 profile 要当陌生人的脚本：读懂，或者别跑。

## 来源

- [Microsoft — Windows Terminal](https://learn.microsoft.com/zh-cn/windows/terminal/)
- [Microsoft — 在 Windows 上安装 PowerShell](https://learn.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell-on-windows)
- [Microsoft — about_Profiles](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_profiles)

---

来源页面: https://winbook.fyi/zh/windows/dev/terminal/
