powershell-windows by sickn33/antigravity-awesome-skills
npx skills add https://github.com/sickn33/antigravity-awesome-skills --skill powershell-windowsWindows 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 调用必须放在括号内。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 用途 | ❌ 不要使用 | ✅ 使用 |
|---|---|---|
| 成功 | ✅ ✓ | [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) |
| ❌ 错误 | ✅ 正确 |
|---|---|
ConvertTo-Json | ConvertTo-Json -Depth 10 |
规则: 处理嵌套对象时,务必指定 -Depth。
| 操作 | 模式 |
|---|---|
| 读取 | `Get-Content "file.json" -Raw |
| 写入 | `$data |
| 错误信息 | 原因 | 修复方法 |
|---|---|---|
| "parameter 'or'" | 缺少括号 | 将 cmdlet 用 () 包裹 |
| "Unexpected token" | Unicode 字符 | 仅使用 ASCII |
| "Cannot find property" | 空对象 | 先检查是否为 null |
| "Cannot convert" | 类型不匹配 | 使用 .ToString() |
# Strict mode
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
# Paths
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Main
try {
# Logic here
Write-Output "[OK] Done"
exit 0
}
catch {
Write-Warning "Error: $_"
exit 1
}
请记住: PowerShell 有独特的语法规则。括号、仅使用 ASCII 字符以及空值检查是必须遵守的。
此技能适用于执行概述中描述的工作流或操作。
每周安装量
883
代码仓库
GitHub 星标数
27.4K
首次出现
2026年1月20日
安全审计
已安装于
opencode733
gemini-cli723
codex684
github-copilot649
cursor599
amp577
Critical patterns and pitfalls for Windows PowerShell.
| ❌ Wrong | ✅ Correct |
|---|---|
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)) |
Rule: Each cmdlet call MUST be in parentheses when using logical operators.
| Purpose | ❌ Don't Use | ✅ Use |
|---|---|---|
| Success | ✅ ✓ | [OK] [+] |
| Error | ❌ ✗ 🔴 | [!] [X] |
| Warning | ⚠️ 🟡 | [*] [WARN] |
| Info | ℹ️ 🔵 | [i] [INFO] |
| Progress | ⏳ | [...] |
Rule: Use ASCII characters only in PowerShell scripts.
| ❌ Wrong | ✅ Correct |
|---|---|
$array.Count -gt 0 | $array -and $array.Count -gt 0 |
$text.Length | if ($text) { $text.Length } |
| ❌ Wrong | ✅ Correct |
|---|---|
"Value: $($obj.prop.sub)" | Store in variable first |
Pattern:
$value = $obj.prop.sub
Write-Output "Value: $value"
| Value | Use |
|---|---|
| Stop | Development (fail fast) |
| Continue | Production scripts |
| SilentlyContinue | When errors expected |
| Pattern | Use |
|---|---|
| Literal path | C:\Users\User\file.txt |
| Variable path | Join-Path $env:USERPROFILE "file.txt" |
| Relative | Join-Path $ScriptDir "data" |
Rule: Use Join-Path for cross-platform safety.
| Operation | Syntax |
|---|---|
| Empty array | $array = @() |
| Add item | $array += $item |
| ArrayList add | `$list.Add($item) |
| ❌ Wrong | ✅ Correct |
|---|---|
ConvertTo-Json | ConvertTo-Json -Depth 10 |
Rule: Always specify -Depth for nested objects.
| Operation | Pattern |
|---|---|
| Read | `Get-Content "file.json" -Raw |
| Write | `$data |
| Error Message | Cause | Fix |
|---|---|---|
| "parameter 'or'" | Missing parentheses | Wrap cmdlets in () |
| "Unexpected token" | Unicode character | Use ASCII only |
| "Cannot find property" | Null object | Check null first |
| "Cannot convert" | Type mismatch | Use .ToString() |
# Strict mode
Set-StrictMode -Version Latest
$ErrorActionPreference = "Continue"
# Paths
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Main
try {
# Logic here
Write-Output "[OK] Done"
exit 0
}
catch {
Write-Warning "Error: $_"
exit 1
}
Remember: PowerShell has unique syntax rules. Parentheses, ASCII-only, and null checks are non-negotiable.
This skill is applicable to execute the workflow or actions described in the overview.
Weekly Installs
883
Repository
GitHub Stars
27.4K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode733
gemini-cli723
codex684
github-copilot649
cursor599
amp577
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
Gemini Interactions API 指南:统一接口、智能体交互与服务器端状态管理
833 周安装
Apollo MCP 服务器:让AI代理通过GraphQL API交互的完整指南
834 周安装
智能体记忆系统构建指南:分块策略、向量存储与检索优化
835 周安装
Scrapling官方网络爬虫框架 - 自适应解析、绕过Cloudflare、Python爬虫库
836 周安装
抽奖赢家选取器 - 随机选择工具,支持CSV、Excel、Google Sheets,公平透明
838 周安装
Medusa 前端开发指南:使用 SDK、React Query 构建电商商店
839 周安装