ワンクリックで
powershell-windows
PowerShell(任务自动化和配置管理框架)Windows 模式。包含关键陷阱、运算符语法(Operator Syntax)和错误处理。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
PowerShell(任务自动化和配置管理框架)Windows 模式。包含关键陷阱、运算符语法(Operator Syntax)和错误处理。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
务实的编码标准—— 简洁、直接、不做过度设计、不写无用注释(Pragmatic coding standards)
性能分析原则。测量、分析与优化技术。
API design principles and decision-making(API 设计原则与决策逻辑)。REST vs GraphQL vs tRPC selection(选择)、response formats(响应格式)、versioning(版本控制)、pagination(分页)。
App Builder(应用构建编排器)主编排器。根据自然语言请求创建全栈应用,确定项目类型、选择技术栈并协调智能体。
Project scaffolding templates(项目脚手架模板)。用于从零创建新项目。包含 12 个技术栈模板。
Architectural decision-making framework(架构决策框架)。Requirements analysis(需求分析)、trade-off evaluation(权衡评估)、ADR documentation(架构决策记录)。Use when making architecture decisions or analyzing system design(用于架构决策与系统设计分析)。
| name | powershell-windows |
| description | PowerShell(任务自动化和配置管理框架)Windows 模式。包含关键陷阱、运算符语法(Operator Syntax)和错误处理。 |
| allowed-tools | Read, Write, Edit, Glob, Grep, Bash |
针对 Windows PowerShell 的核心模式与关键陷阱。
| [FAIL] 错误做法 | [OK] 正确做法 |
|---|---|
if (Test-Path "a" -or Test-Path "b") | if ((Test-Path "a") -or (Test-Path "b")) |
if (Get-Item $x -and $y -eq 5) | if ((Get-Item $x) -and ($y -eq 5)) |
准则: 在使用逻辑运算符时,每一个 Cmdlet(命令)的调用必须封装在圆括号内。
| 用途 | [FAIL] 禁止使用 | [OK] 推荐使用 |
|---|---|---|
| 成功 | [OK] OK | [OK] [+] |
| 错误 | [FAIL] X [CRITICAL] | [!] [X] |
| 警告 | [WARN] [SUGGESTION] | [*] [WARN] |
| 信息 | ℹ | [i] [INFO] |
| 进度 | ⏳ | [...] |
准则: 在 PowerShell 脚本中仅使用 ASCII(ASCII 码)字符。
| [FAIL] 错误做法 | [OK] 正确做法 |
|---|---|
$array.Count -gt 0 | $array -and $array.Count -gt 0 |
$text.Length | if ($text) { $text.Length } |
推荐做法: 先存储到变量中,再进行内插。
$value = $obj.prop.sub
Write-Output "Value: $value"
| 取值 | 使用场景 |
|---|---|
| Stop | 开发阶段(快速失败) |
| Continue | 生产环境脚本 |
| SilentlyContinue | 预期可能会发生错误时 |
| 模式 | 用途 |
|---|---|
| 字面量路径 | C:\Users\User\file.txt |
| 变量路径 | Join-Path $env:USERPROFILE "file.txt" |
| 相对路径 | Join-Path $ScriptDir "data" |
准则: 使用 Join-Path 以确保跨平台的路径安全性。
| 操作项 | 语法 |
|---|---|
| 空数组 | $array = @() |
| 添加元素 | $array += $item |
| ArrayList 添加 | $list.Add($item) | Out-Null |
| [FAIL] 错误做法 | [OK] 正确做法 |
|---|---|
ConvertTo-Json | ConvertTo-Json -Depth 10 |
准则: 处理嵌套对象时,务必显式指定 -Depth。
| 操作项 | 模式 |
|---|---|
| 读取 | Get-Content "file.json" -Raw | ConvertFrom-Json |
| 写入 | $data | ConvertTo-Json -Depth 10 | Out-File "file.json" -Encoding UTF8 |
| 错误消息 | 原因 | 修复方案 |
|---|---|---|
| "parameter 'or'" | 缺失圆括号 | 使用 () 封装 Cmdlet |
| "Unexpected token" | 存在 Unicode 字符 | 仅保留 ASCII 字符 |
| "Cannot find property" | 对象为空(Null) | 先执行空值检查 |
| "Cannot convert" | 类型不匹配 | 使用 .ToString() 转换 |
# 开启严格模式
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
# 路径初始化
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# 主程序逻辑
try {
# 在此处编写业务逻辑
Write-Output "[OK] Done"
exit 0
}
catch {
Write-Warning "Error: $_"
exit 1
}
谨记: PowerShell 具有独特的语法规则。圆括号的使用、仅限 ASCII 以及空值检查是不可逾越的底线。