Communityコーディング&開発github.com

sickn33/powershell-windows

PowerShell Windowsのパターン集。重要な落とし穴、演算子構文、エラーハンドリング。

powershell-windows とは?

このスキルは、Windows環境でのPowerShellコマンドレットやスクリプト作成において、開発者が陥りがちな重要な落とし穴や、演算子の正しい構文、堅牢なエラーハンドリングのパターンを提供します。PowerShellの独自の構文(比較演算子 `-eq`、代入演算子 `=` の違いなど)や、パイプラインの挙動、`$Error` 自動変数の扱い方など、C#やPythonとは異なる点を明確にし、ミスを減らします。主にWindows PowerShell 5.1以上とPowerShell 7.xに対応し、ファイル操作、レジストリ変更、WMI/CIMクエリ、Active Directory操作など、Windows管理タスク全般で役立ちます。記述されたSKILL.mdに基づき、具体的なコード例とともに適切なコーディングパターンを学習できます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/powershell-windows

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

powershell-windows は何をしますか?

PowerShell Windowsのパターン集。重要な落とし穴、演算子構文、エラーハンドリング。

目次

演算子の落とし穴

PowerShellでは、C系言語と異なる演算子を使用します。

操作PowerShell間違いやすい例
等価比較-eq== (常に間違い)
代入=条件式内で = は代入
パターンマッチ-match, -like-contains はコレクション用
論理AND-and&& (旧バージョン非対応)
# 間違い
if ($a == $b) { ... }   # $a に $b を代入し、常に真

# 正しい
if ($a -eq $b) { ... }

エラーハンドリング

PowerShellのエラーは終了エラーと非終了エラーに分かれます。

  • 非終了エラーは try/catch でキャッチされません。-ErrorAction Stop が必要です。
  • $Error 自動変数はすべてのエラーを蓄積します。適宜クリアしてください。
# 非終了エラーをキャッチする
Try {
    Get-Item "C:\Nonexistent" -ErrorAction Stop
} Catch {
    Write-Error "ファイルが見つかりません: $_"
}

# $Error のクリア
$Error.Clear()

パイプラインの動作

パイプラインはオブジェクトを渡します。文字列ではありません。

# 間違い: パイプラインを文字列結合に使う
"Hello", "World" | Write-Host

# 正しい: ForEach-Object や -join を使用
"Hello", "World" | ForEach-Object { "アイテム: $_" }
"Hello", "World" -join ", "

よくある間違い

  1. Write-Host の多用: 出力の制御を妨げます。代わりに Write-Output または Write-Verbose を使用。
  2. $null の比較: $null -eq $variable と書く($variable -eq $null は配列で失敗)。
  3. プロパティの展開忘れ: (Get-Process).Name のように括弧で囲む。
  4. 動的パラメータ: スプラッティング (@) を使うと可読性が向上。
# 間違い: 位置パラメータの乱用
Get-Process -Name "notepad"

# 正しい: スプラッティング
$params = @{
    Name = "notepad"
    ErrorAction = "Stop"
}
Get-Process @params

推奨パターン

  • 常に -ErrorAction Stop でエラーをキャッチ可能にする。
  • Set-StrictMode -Version Latest をスクリプトの先頭に追加する。
  • レジストリ操作は -ErrorAction Stop と Try/Catch の組み合わせが安全。
  • 外部コマンド呼び出し(例: net.exe)の終了コードは $LASTEXITCODE で確認する。
# 外部コマンドのエラーチェック
net user TestUser Password123 /add
if ($LASTEXITCODE -ne 0) {
    throw "net user コマンドが失敗しました。終了コード: $LASTEXITCODE"
}

参考リンク

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

sickn33/3d-web-experience

Expert in building 3D experiences for the web - Three.js, React Three Fiber, Spline, WebGL, and interactive 3D scenes. Covers product configurators, 3D portfolios, immersive websites, and bringing depth to web experiences.

sickn33/agent-memory-mcp

A hybrid memory system that provides persistent, searchable knowledge management for AI agents (Architecture, Patterns, Decisions).

sickn33/agent-memory-systems

Memory is the cornerstone of intelligent agents. Without it, every interaction starts from zero. This skill covers the architecture of agent memory: short-term (context window), long-term (vector stores), and the cognitive architectures that organize them.

sickn33/ai-agents-architect

Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration.

sickn33/api-documentation-generator

Generate comprehensive, developer-friendly API documentation from code, including endpoints, parameters, examples, and best practices

sickn33/api-patterns

API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.

sickn33/api-security-best-practices

Implement secure API design patterns including authentication, authorization, input validation, rate limiting, and protection against common API vulnerabilities

sickn33/app-store-optimization

Complete App Store Optimization (ASO) toolkit for researching, optimizing, and tracking mobile app performance on Apple App Store and Google Play Store

sickn33/architecture

Architectural decision-making framework. Requirements analysis, trade-off evaluation, ADR documentation. Use when making architecture decisions or analyzing system design.

sickn33/audio-transcriber

Transform audio recordings into professional Markdown documentation with intelligent summaries using LLM integration

sickn33/aws-serverless

Specialized skill for building production-ready serverless applications on AWS. Covers Lambda functions, API Gateway, DynamoDB, SQS/SNS event-driven patterns, SAM/CDK deployment, and cold start optimization.

sickn33/backend-architect

Expert backend architect specializing in scalable API design, microservices architecture, and distributed systems.

sickn33/backend-dev-guidelines

You are a senior backend engineer operating production-grade services under strict architectural and reliability constraints. Use when routes, controllers, services, repositories, express middleware, or prisma database access.

sickn33/bash-linux

Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

sickn33/bash-scripting

Bash scripting workflow for creating production-ready shell scripts with defensive patterns, error handling, and testing.

sickn33/brainstorming

Use before creative or constructive work (features, architecture, behavior). Transforms vague ideas into validated designs through disciplined reasoning and collaboration.

sickn33/browser-automation

Browser automation powers web testing, scraping, and AI agent interactions. The difference between a flaky script and a reliable system comes down to understanding selectors, waiting strategies, and anti-detection patterns.

sickn33/browser-extension-builder

Expert in building browser extensions that solve real problems - Chrome, Firefox, and cross-browser extensions. Covers extension architecture, manifest v3, content scripts, popup UIs, monetization strategies, and Chrome Web Store publishing.

sickn33/bullmq-specialist

BullMQ expert for Redis-backed job queues, background processing, and reliable async execution in Node.js/TypeScript applications.

sickn33/bun-development

Fast, modern JavaScript/TypeScript development with the Bun runtime, inspired by [oven-sh/bun](https://github.com/oven-sh/bun).

関連スキル