[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-2dbf18b2-ab96-4426-8075-97950b581fca":3,"$fUD-t7tC6BPNvJ0pbprsJ6G48Uy7UZd61uqFzFNtZiWQ":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"2dbf18b2-ab96-4426-8075-97950b581fca","powershell-windows","PowerShell Windows 模式。关键陷阱、运算符语法、错误处理。","cat_life_career","mod_other","sickn33,other","---\nname: powershell-windows\ndescription: \"PowerShell Windows patterns. Critical pitfalls, operator syntax, error handling.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# PowerShell Windows Patterns\n\n> Critical patterns and pitfalls for Windows PowerShell.\n\n---\n\n## 1. Operator Syntax Rules\n\n### CRITICAL: Parentheses Required\n\n| ❌ Wrong | ✅ Correct |\n|----------|-----------|\n| `if (Test-Path \"a\" -or Test-Path \"b\")` | `if ((Test-Path \"a\") -or (Test-Path \"b\"))` |\n| `if (Get-Item $x -and $y -eq 5)` | `if ((Get-Item $x) -and ($y -eq 5))` |\n\n**Rule:** Each cmdlet call MUST be in parentheses when using logical operators.\n\n---\n\n## 2. Unicode\u002FEmoji Restriction\n\n### CRITICAL: No Unicode in Scripts\n\n| Purpose | ❌ Don't Use | ✅ Use |\n|---------|-------------|--------|\n| Success | ✅ ✓ | [OK] [+] |\n| Error | ❌ ✗ 🔴 | [!] [X] |\n| Warning | ⚠️ 🟡 | [*] [WARN] |\n| Info | ℹ️ 🔵 | [i] [INFO] |\n| Progress | ⏳ | [...] |\n\n**Rule:** Use ASCII characters only in PowerShell scripts.\n\n---\n\n## 3. Null Check Patterns\n\n### Always Check Before Access\n\n| ❌ Wrong | ✅ Correct |\n|----------|-----------|\n| `$array.Count -gt 0` | `$array -and $array.Count -gt 0` |\n| `$text.Length` | `if ($text) { $text.Length }` |\n\n---\n\n## 4. String Interpolation\n\n### Complex Expressions\n\n| ❌ Wrong | ✅ Correct |\n|----------|-----------|\n| `\"Value: $($obj.prop.sub)\"` | Store in variable first |\n\n**Pattern:**\n```\n$value = $obj.prop.sub\nWrite-Output \"Value: $value\"\n```\n\n---\n\n## 5. Error Handling\n\n### ErrorActionPreference\n\n| Value | Use |\n|-------|-----|\n| Stop | Development (fail fast) |\n| Continue | Production scripts |\n| SilentlyContinue | When errors expected |\n\n### Try\u002FCatch Pattern\n\n- Don't return inside try block\n- Use finally for cleanup\n- Return after try\u002Fcatch\n\n---\n\n## 6. File Paths\n\n### Windows Path Rules\n\n| Pattern | Use |\n|---------|-----|\n| Literal path | `C:\\Users\\User\\file.txt` |\n| Variable path | `Join-Path $env:USERPROFILE \"file.txt\"` |\n| Relative | `Join-Path $ScriptDir \"data\"` |\n\n**Rule:** Use Join-Path for cross-platform safety.\n\n---\n\n## 7. Array Operations\n\n### Correct Patterns\n\n| Operation | Syntax |\n|-----------|--------|\n| Empty array | `$array = @()` |\n| Add item | `$array += $item` |\n| ArrayList add | `$list.Add($item) | Out-Null` |\n\n---\n\n## 8. JSON Operations\n\n### CRITICAL: Depth Parameter\n\n| ❌ Wrong | ✅ Correct |\n|----------|-----------|\n| `ConvertTo-Json` | `ConvertTo-Json -Depth 10` |\n\n**Rule:** Always specify `-Depth` for nested objects.\n\n### File Operations\n\n| Operation | Pattern |\n|-----------|---------|\n| Read | `Get-Content \"file.json\" -Raw | ConvertFrom-Json` |\n| Write | `$data | ConvertTo-Json -Depth 10 | Out-File \"file.json\" -Encoding UTF8` |\n\n---\n\n## 9. Common Errors\n\n| Error Message | Cause | Fix |\n|---------------|-------|-----|\n| \"parameter 'or'\" | Missing parentheses | Wrap cmdlets in () |\n| \"Unexpected token\" | Unicode character | Use ASCII only |\n| \"Cannot find property\" | Null object | Check null first |\n| \"Cannot convert\" | Type mismatch | Use .ToString() |\n\n---\n\n## 10. Script Template\n\n```powershell\n# Strict mode\nSet-StrictMode -Version Latest\n$ErrorActionPreference = \"Continue\"\n\n# Paths\n$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path\n\n# Main\ntry {\n    # Logic here\n    Write-Output \"[OK] Done\"\n    exit 0\n}\ncatch {\n    Write-Warning \"Error: $_\"\n    exit 1\n}\n```\n\n---\n\n> **Remember:** PowerShell has unique syntax rules. Parentheses, ASCII-only, and null checks are non-negotiable.\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,56,793,"2026-05-16 13:34:36",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"其他","other","mdi-page-next-outline","其他类型Skill",5,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"职场发展","career","mdi-briefcase-outline","面试准备、简历优化、职业规划",4,575,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"81a53919-979d-4efd-ab62-7723536c897b","1.0.0","powershell-windows.zip",1952,"uploads\u002Fskills\u002F2dbf18b2-ab96-4426-8075-97950b581fca\u002Fpowershell-windows.zip","5d8beffaa97f530f68407db4d9fe1ceb8b84f880f991e7c779c2a48434385a03","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":3930}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]