Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Powershell Windows

ASecurity

当在 Windows 上编写或调试 PowerShell 脚本(含 Agent 生成的自动化脚本)时使用;做规避运算符/Unicode/空值/JSON 等高频陷阱,产出健壮可执行的 .ps1 脚本与命令;不适用于 Bash/Linux shell 脚本或 pwsh 跨平台高级特性教学;触发词:PowerShell、Windows 脚本、.ps1、cmdlet、Test-Path、ConvertTo-Json、ErrorActionPreference

3 stars
0 votes
0 copies
2 views
Added 9/19/2026
ai-agentsshellbashgitdevops

Works with

cursorcli

Security Analysis

A100/100

Scanned 9/19/2026

$npx -y skills add findscripter/everything-skills --skill powershell-windows --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Powershell Windows?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Powershell Windows
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/findscripter-powershell-windows/badge)](https://www.skillsdirectory.com/skills/findscripter-powershell-windows)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: powershell-windows
title: PowerShell Windows 实战
description: 当在 Windows 上编写或调试 PowerShell 脚本(含 Agent 生成的自动化脚本)时使用;做规避运算符/Unicode/空值/JSON 等高频陷阱,产出健壮可执行的 .ps1 脚本与命令;不适用于 Bash/Linux shell 脚本或 pwsh 跨平台高级特性教学;触发词:PowerShell、Windows 脚本、.ps1、cmdlet、Test-Path、ConvertTo-Json、ErrorActionPreference
domain: 研发/devops
triggers: [PowerShell, Windows 脚本, .ps1, cmdlet, Test-Path, ConvertTo-Json, ErrorActionPreference, Join-Path, PowerShell 报错, Unexpected token]
tags: [powershell, windows, 脚本, shell, automation, error-handling, cmdlet]
level: 进阶
status: stable
agents: [claude-code, codex, cursor, gemini-cli]
tools: [powershell, pwsh]
requires: []
related: []
combines_with: []
license: MIT
source: sickn33/agentic-awesome-skills
source_license: MIT
---
## 何时使用

在 **Windows + PowerShell** 环境下编写、生成或调试脚本时,用本技能逐项规避 PowerShell 特有的语法与运行期陷阱,让脚本一次跑通而非反复报「Unexpected token / parameter 'or' / Cannot find property」。尤其适合 Agent 自动生成 `.ps1` 时做产出前自检。

不该用:

- 写 **Bash / sh / zsh** 等 POSIX shell 脚本 —— 语法规则完全不同。
- 需要 pwsh 跨平台远程、DSC、模块开发等深度专题 —— 本技能只覆盖高频通用陷阱。
- 任务本身与脚本无关(仅是在 Windows 上跑某个程序)。

## 步骤 / 指令

按以下清单逐条核对生成的脚本:

1. **运算符必须加括号**:逻辑运算符两侧的 cmdlet 调用各自用 `()` 包起来。
2. **脚本内只用 ASCII**:日志/输出禁用 emoji 与 Unicode 符号,改用 `[OK] [X] [WARN] [INFO] [...]` 标记(Unicode 会触发 `Unexpected token`)。
3. **先判空再访问**:访问 `.Count` / `.Length` / 属性前先确认对象非 `$null`。
4. **复杂插值先落变量**:深层属性 `$obj.prop.sub` 先赋给变量再插值。
5. **显式错误策略 + try/catch**:开发用 `Stop` 快速失败,生产脚本用 `Continue`;`catch` 收口、`finally` 清理,不要在 `try` 内 `return`。
6. **路径用 `Join-Path`**:除非字面常量路径,否则拼接路径一律 `Join-Path`。
7. **JSON 永远带 `-Depth`**:`ConvertTo-Json` 默认深度仅 2,嵌套对象必加 `-Depth 10`。
8. **数组/集合用正确写法**:见示例。
9. **收尾**:用文末脚本模板包裹(StrictMode + 错误策略 + try/catch + exit code)。

## 示例

运算符(每个 cmdlet 调用都要括号):

```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)) { }
```

空值检查与复杂插值:

```powershell
# 判空再取 .Count / .Length
if ($array -and $array.Count -gt 0) { }
if ($text) { $text.Length }

# 深层属性先落变量再插值
$value = $obj.prop.sub
Write-Output "Value: $value"
```

数组与 JSON:

```powershell
$array = @()                       # 空数组
$array += $item                    # 追加
$list.Add($item) | Out-Null        # ArrayList 追加(吞返回值)

# 读:Get-Content "file.json" -Raw | ConvertFrom-Json
$data | ConvertTo-Json -Depth 10 | Out-File "file.json" -Encoding UTF8
```

脚本模板(直接套用):

```powershell
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
}
```

常见报错速查:

| 报错 | 成因 | 修复 |
|---|---|---|
| parameter 'or' | 逻辑运算符旁的 cmdlet 没加括号 | 把 cmdlet 调用包进 `()` |
| Unexpected token | 脚本含 Unicode/emoji | 全程改 ASCII |
| Cannot find property | 访问了 `$null` 对象 | 先判空 |
| Cannot convert | 类型不匹配 | 显式 `.ToString()` |

## 注意事项

- **括号、ASCII-only、判空** 三条是硬约束,不可省。
- `ConvertTo-Json` 漏写 `-Depth` 会静默截断嵌套数据,排查极费时。
- `Out-File` 写 JSON 给其它工具读时显式 `-Encoding UTF8`,避免 BOM/UTF-16 乱码。
- StrictMode 下未定义变量会抛错,这是好事;但要确保所有变量先初始化。
- 本技能针对 Windows PowerShell 5.1 与 pwsh 通用陷阱;版本差异行为请以目标环境实测为准,勿把输出当作免测依据。

## 互见

- related:`busybox-on-windows` —— 当 Windows 上更想直接用 `ls/grep/sed` 等 UNIX 命令而非 PowerShell 时
- related:`systematic-debugger` —— 脚本报错根因定位的通用方法论
- combines_with:`github-actions-author` —— CI 中编写 Windows runner 的 PowerShell step

---

采编自 sickn33/antigravity-awesome-skills(MIT)。

Attribution

findscripterfindscripter
View sourceSee grades on GitHubMore from findscripter →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698621 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →