i18n/zh-TW/powershell-windows/SKILL.md
PowerShell Windows 模式。關鍵陷阱、運算子語法、錯誤處理。
npx skillsauth add tai-ch0802/skills-bundle powershell-windowsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Windows PowerShell 的關鍵模式與陷阱。
| ❌ 錯誤 | ✅ 正確 |
|---------|---------|
| 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 呼叫都必須在括號中。
| 用途 | ❌ 不要用 | ✅ 要用 | |------|-----------|---------| | 成功 | ✅ ✓ | [OK] [+] | | 錯誤 | ❌ ✗ 🔴 | [!] [X] | | 警告 | ⚠️ 🟡 | [*] [WARN] | | 資訊 | ℹ️ 🔵 | [i] [INFO] | | 進度 | ⏳ | [...] |
規則: PowerShell 腳本中僅使用 ASCII 字元。
| ❌ 錯誤 | ✅ 正確 |
|---------|---------|
| $array.Count -gt 0 | $array -and $array.Count -gt 0 |
| $text.Length | if ($text) { $text.Length } |
| ❌ 錯誤 | ✅ 正確 |
|---------|---------|
| "Value: $($obj.prop.sub)" | 先存入變數 |
模式:
$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 |
| ❌ 錯誤 | ✅ 正確 |
|---------|---------|
| 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 物件 | 先檢查 null | | "Cannot convert" | 型別不匹配 | 使用 .ToString() |
# 嚴格模式
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
# 路徑
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# 主程式
try {
# 邏輯放這裡
Write-Output "[OK] 完成"
exit 0
}
catch {
Write-Warning "錯誤:$_"
exit 1
}
記住: PowerShell 有獨特的語法規則。括號、僅 ASCII 和 null 檢查是不可妥協的。
development
Unified testing skill — TDD workflow, unit/integration patterns, E2E/Playwright strategies. Replaces tdd-workflow + testing-patterns + webapp-testing.
testing
Security-first skill vetting for AI agents. Use before installing any skill from ClawdHub, GitHub, or other sources. Checks for red flags, permission scope, and suspicious patterns.
development
Spec-Driven Development (SDD): A structured workflow (Requirement -> Analysis -> Implementation) enforcing explicit documentation before coding.
development
Methodologies for System Analysis (SA), focusing on technical architecture, data flow modeling, and API design.