技能 powershell-windows
📦

powershell-windows

安全 ⚙️ 外部命令

Master PowerShell Windows Scripting Patterns

Avoid common PowerShell pitfalls that cause script failures. Learn proper operator syntax, error handling, and Windows-specific patterns for reliable automation.

支援: Claude Codex Code(CC)
🥉 74 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「powershell-windows」。 Check if file exists or directory exists

預期結果:

Use: if ((Test-Path "file.txt") -or (Test-Path "folder")) - Each cmdlet must be wrapped in parentheses when using logical operators

正在使用「powershell-windows」。 Safely get array length

預期結果:

Use: if ($array -and $array.Count -gt 0) - Always verify the array exists before accessing properties

正在使用「powershell-windows」。 Convert nested object to JSON

預期結果:

Use: $data | ConvertTo-Json -Depth 10 - Always specify depth parameter for nested objects to avoid truncation

安全審計

安全
v1 • 2/24/2026

Static analysis detected 34 patterns but all are false positives. The SKILL.md file is documentation only, containing PowerShell syntax examples and best practices. No executable code or security risks present. The skill is a reference guide for proper PowerShell scripting patterns on Windows.

1
已掃描檔案
173
分析行數
1
發現項
1
審計總數
審計者: claude

品質評分

38
架構
100
可維護性
85
內容
50
社群
100
安全
91
規範符合性

你能建構什麼

DevOps Engineer Scripting

Create reliable Windows automation scripts with proper error handling and null safety for CI/CD pipelines

System Administrator Reference

Quick reference for PowerShell syntax rules and common pitfalls when maintaining legacy scripts

Developer Learning Resource

Learn PowerShell best practices and avoid common mistakes when adding Windows scripting to your toolkit

試試這些提示

Basic Syntax Question
What is the correct PowerShell syntax for checking if a file exists OR another condition is true?
Error Handling Pattern
Show me the proper try-catch-finally pattern for PowerShell scripts that need to clean up resources
Null Safety Check
How do I safely check if an array has items before accessing its Count property in PowerShell?
JSON File Operations
What is the correct way to read and write JSON files in PowerShell with nested objects?

最佳實務

  • Wrap each cmdlet in parentheses when using logical operators like -or and -and
  • Always check for null before accessing object properties or methods
  • Use Join-Path for building file paths instead of string concatenation
  • Set ErrorActionPreference appropriately for your environment (Stop for dev, Continue for production)
  • Specify -Depth parameter when converting nested objects to JSON

避免

  • Using unicode or emoji characters in PowerShell scripts - use ASCII markers like [OK] instead
  • Accessing properties without null checks - will cause runtime errors on null values
  • Using ConvertTo-Json without -Depth parameter - nested objects will be truncated
  • Placing return statements inside try blocks - use finally for cleanup and return after

常見問題

Why do PowerShell logical operators require extra parentheses?
PowerShell parses cmdlets and operators differently than other languages. Each cmdlet call must be wrapped in parentheses so the parser correctly identifies where each command ends before applying the logical operator.
What is the safest way to handle file paths in PowerShell?
Use Join-Path instead of string concatenation. This handles path separators correctly across different Windows versions and avoids issues with trailing backslashes.
Why should I avoid unicode characters in PowerShell scripts?
Unicode characters can cause parsing errors on systems with different encodings. Using ASCII markers like [OK], [WARN], or [ERROR] ensures compatibility across all Windows environments.
What ErrorActionPreference should I use in production?
Use 'Continue' in production to allow scripts to handle errors gracefully. Use 'Stop' during development to catch issues early. Use 'SilentlyContinue' when errors are expected and handled.
How do I properly convert nested objects to JSON?
Always specify the -Depth parameter with ConvertTo-Json. The default depth is 2, which truncates nested objects. Use -Depth 10 or higher for deeply nested structures.
What is the correct pattern for null-safe array access?
Check both the array and its count: if ($array -and $array.Count -gt 0). This prevents errors when the array is null or undefined before accessing the Count property.

開發者詳情

檔案結構

📄 SKILL.md