360 Secure SkillHub
360 安全技能中心

probe

面向 Windows 的自包含安装包:优先探测或下载 PowerShell 7,安装 ripgrep、fd、fzf、bat、delta、jq,修复中文输出乱码,并把 pwsh 设为默认 shell;幂等、免管理员、含离线兜底与体检脚本。

分类:开发
yujianyu
yujianyu
热度 0.97
最近更新 2026-10-22 14:26:22

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add yujianyu/probe-automation-2
兼容性
通用兼容
联网要求
需要联网
数据出网
数据不出本机
Metadata
name
powershell7-toolkit
version
1.1.0
display_name
PowerShell 7 工具链
display_name_en
PowerShell 7 Toolkit
author
欣欣 (YUJIANYU)
license
MIT
agent_created
true
category
development
description
在 Windows 上部署 PowerShell 7 与 Rust 高性能命令行工具链(ripgrep / fd / fzf / bat / delta / jq),根治中文输出乱码,并把 pwsh 设为系统默认 shell。跨机器自包含、幂等、免管理员、断网可装。
description_zh
在 Windows 上部署 PowerShell 7 与 Rust 高性能命令行工具链(ripgrep / fd / fzf / bat / delta / jq),根治中文输出乱码,并把 pwsh 设为系统默认 shell。跨机器自包含、幂等、免管理员、断网可装。
description_en
Deploys PowerShell 7 and the Rust high-performance CLI toolchain (ripgrep / fd / fzf / bat / delta / jq) on Windows, fixes Chinese mojibake in shell output, and makes pwsh the default shell. Self-contained, idempotent, no admin rights required, works offline.
tags
["powershell","pwsh","ripgrep","rust","utf8","编码","命令行","windows","工具链","developer"]
requires
[]
metadata
{"label":"PowerShell 7 工具链"}

PowerShell 7 工具链

一套自包含、幂等、跨机器的部署包。任何 AI 助手都可以照着本文件执行,无需联网查资料。

一、什么时候用这个技能

  • 要装 / 升级 PowerShell 7(pwsh)
  • 中文在 PowerShell / cmd / 第三方工具输出里乱码
  • 想用 ripgrep 等 Rust 工具加速检索
  • 要把 pwsh 设为系统默认 shell

二、安装(一条命令)

powershell -ExecutionPolicy Bypass -File "<技能目录>\scripts\install.ps1"

它的策略是「探测优先 → 自动下载兜底」:

  1. 先探测系统里已装的 pwsh —— 扫 Program Files\PowerShell\7、用户目录、注册表 App Paths、PATH、scoop/chocolatey、Store 版(WindowsApps)。找到就直接复用,绝不重复安装
  2. 找不到才找本地 zip(Downloads / 桌面 / 下载 / 迅雷下载 / Documents / TEMP)
  3. 本地也没有才自动下载:官方 API 查最新版 → 三个国内镜像依次回退 → 微软 aka.ms 官方短链 → 内置固定版本表兜底(断网也能装)

常用参数:

参数 说明
-ZipPath "D:\xxx\PowerShell-7.6.7-win-x64.zip" 指定安装包(跳过自动搜索)
-ToolsRoot "D:\Tools\ps7" 安装根目录(默认 %LOCALAPPDATA%\ps7-toolkit)
-Mirror "https://your.mirror/" 自定义下载镜像(会插到内置列表最前)
-SkipDefaults 只装不配(不改系统默认)
-SkipRustTools 只装 PowerShell 7
-Force 强制重装(忽略已安装检测)
-CheckOnly 只体检,不做任何改动

特性:幂等(重复跑只补缺失项)、免管理员权限、不依赖 Python、不写死盘符、断网可用、卸载只需删目录 + 3 个注册表项。

三、日常使用规范(装完之后必须遵守)

  1. 执行命令优先用 pwsh:
    & "$env:LOCALAPPDATA\ps7-toolkit\ps7\pwsh.exe" -NoProfile -File script.ps1
    
    或直接敲 pwsh(已在 PATH)。
  2. 复杂脚本写成 .ps1 文件再用 -File 跑,不要用 -Command 内联 —— 内联时嵌套引号会被外层解析拆散。
  3. 给 PowerShell 5.1 跑的 .ps1 文件必须存成 UTF-8 with BOM;给 pwsh 跑的用普通 UTF-8 即可。
    • 原因:5.1 读 .ps1 按 ANSI(GBK) 解析,脚本里含中文注释会报"字符串缺少终止符"。
  4. 文本检索用 rg,不用 Select-String(实测快 11 倍):
    rg -n --no-heading -e "关键词" -g "*.py" C:\path
    
  5. 输出乱码时先查 [Console]::OutputEncoding 和 $OutputEncoding 是否为 UTF-8(profile 已自动设置)。

四、绝对不要做的事

禁止 原因
改 HKLM\...\Nls\CodePage\ACP = 65001 会让老的 GBK 程序(部分国产软件/游戏)全部乱码,风险远大于收益
劫持 powershell.exe 指向 pwsh 系统组件与大量安装脚本硬依赖 C:\Windows\System32\WindowsPowerShell\v1.0\,改了会导致装软件失败
用 Add-Type 编译 .NET 代码 部分 AI 客户端的安全策略会直接拦截(会改用 Python 或 Expand-Archive 替代)
在 Bash 里直接调 powershell 某些客户端策略会拦("Invoking PowerShell from Bash bypasses security checks"),改写成脚本文件执行

五、能力清单(安装后可用)

工具 用途 替代
pwsh 7.x 主力 shell(UTF-8 默认、&& 链、三元 ?:、??、ForEach-Object -Parallel,性能约 2 倍) Windows PowerShell 5.1
rg (ripgrep) 极速递归检索,自带 .gitignore 规则 Select-String / findstr
fd 极速文件名查找 Get-ChildItem
fzf 模糊查找(可接管 Ctrl+R 历史搜索) —
bat 带语法高亮的 cat(配 delta 更好看) cat / type
delta git diff 高亮 —
jq JSON 处理 ConvertFrom-Json

六、文件清单

SKILL.md                          本文件
assets/icon.png                   512x512 图标
scripts/install.ps1               主安装器(幂等,跨机器)
scripts/setup-defaults.ps1        默认化(profile/注册表/文件关联/快捷方式/终端/VSCode)
scripts/verify.ps1                体检脚本,输出诊断报告
references/troubleshooting.md     踩坑与排错
CHANGELOG.md                      版本记录

七、给终端用户的三步说明

  1. 打开 PowerShell,执行: powershell -ExecutionPolicy Bypass -File "脚本路径\install.ps1"
  2. 重启终端 / 常用应用(PATH 才会刷新)
  3. 验证:pwsh -v 应显示 7.x;rg --version 应显示 ripgrep

八、这个技能会改动什么(知情同意)

安装过程全部在当前用户范围内,不需要管理员权限,不触碰 HKEY_LOCAL_MACHINE,也不会改动系统区域设置(不改 ACP)。

会做的改动:

改动 位置 如何撤销
写入可执行文件 %LOCALAPPDATA%\ps7-toolkit(或 -ToolsRoot 指定目录) 删除该目录
追加用户 PATH HKCU\...\Environment 的 Path 删掉该项里的 ps7-toolkit 路径
写入 profile %USERPROFILE%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1(7.x)%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1(5.1) 删除该文件或去掉本技能追加的段落
注册 pwsh 路径 HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\pwsh.exe 删除该键
关联 .ps1 双击行为 HKCU\Software\Microsoft\Classes\.ps1\shell\open\command 删除该键
默认控制台 HKCU\...\Explorer\Advanced 的 DelegationConsole(仅当检测到 Windows Terminal 时) 删除该值
建开始菜单快捷方式 %APPDATA%\Microsoft\Windows\Start Menu\Programs 删除对应快捷方式

网络行为:仅在需要下载时访问 api.github.com(查版本与真实下载地址)、github.com(下载安装包)、gh-proxy.com / ghfast.top / ghproxy.net(国内加速镜像)、aka.ms(微软官方短链)。不收集任何用户数据、不上报统计、不请求 API Key。

只读体检(verify.ps1)与只装不改(-SkipDefaults)不产生任何持久化改动。