Powershell Refactorのロゴ

Powershell Refactor

コミュニティ
mickpletcher
powershell-refactor

Refactor existing PowerShell scripts to simplify flow, reduce duplication, standardize naming and structure, and tighten behavior without changing the intended outcome.

概要

公開者mickpletcher
リポジトリAI-Skills
スキル名powershell-refactor
スター
21
フォーク
3
同梱ファイル
3
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 3個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    mickpletcherがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキルPowershell RefactorをTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/mickpletcher/AI-Skills/tree/main/claude/skills/powershell-refactor
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mickpletcher/AI-Skills.git /tmp/AI-Skills
mkdir -p .claude/skills
cp -r /tmp/AI-Skills/claude/skills/powershell-refactor .claude/skills/powershell-refactor
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでPowershell Refactorを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあると、モデルが自動的にPowershell Refactorを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Powershell Refactorは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、未使用のスキルにはコストがかかりません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

PowerShell Refactor Skill

Intent

Use this skill to improve an existing PowerShell script that already works or mostly works but needs cleanup. The goal is to make the code smaller, clearer, more idiomatic, and easier to maintain without introducing unnecessary abstractions or changing the script's job.

Use When

  • A PowerShell script feels repetitive, bloated, inconsistent, or hard to follow
  • Function names, parameter names, or output patterns need to be standardized
  • The user wants a script simplified, tightened, cleaned up, or refactored
  • The script should be aligned with practical PowerShell conventions for real admin automation

Do Not Use When

  • The main task is to create a brand new script from scratch
  • The request is mostly about documentation, README writing, or tutorial content
  • The user wants a major architecture redesign instead of a focused refactor
  • The script's expected behavior is unclear and changing it would be risky

Workflow

  1. Read the existing script first and identify the real behavior that must stay intact.
  2. Find the highest value cleanup targets:
    • duplicated logic
    • dead code
    • inconsistent naming
    • unclear control flow
    • noisy error handling
    • unnecessary wrappers or abstractions
  3. Refactor in place with the smallest set of edits that materially improves the script.
  4. Prefer native PowerShell patterns:
    • approved verbs
    • clear parameter blocks
    • pipeline-aware logic when it adds value
    • try and catch only where they improve control and diagnostics
    • Write-Verbose, Write-Warning, and structured output instead of ad hoc console noise
  5. Keep function boundaries practical. Split code only when it improves readability or reuse in a clear way.
  6. Recheck for behavior drift, naming consistency, and obvious lint or test issues before finishing.

Scope Presets

Let the user control how aggressive the pass is. Default to full cleanup when no preset is named:

  • naming only: rename functions to approved verbs, standardize parameter and variable casing, touch nothing else
  • deduplication only: collapse repeated logic into shared functions or loops, keep all names and structure otherwise
  • full cleanup: the complete workflow above

When the user names a preset, stay inside it even when other cleanup targets are visible; list the out-of-scope findings at the end instead of fixing them.

PSScriptAnalyzer Alignment

Run Invoke-ScriptAnalyzer on the script before and after when it is available, honoring any PSScriptAnalyzerSettings.psd1 in the repo. Fix the violations that fall inside the chosen scope preset, and list any remaining ones with a one-line reason they were left, such as a deliberate Write-Host for interactive output. The refactor should never introduce new violations.

Change Summary

End every refactor with a before-and-after summary so the user can review the pass at a glance:

text
Refactor Summary
- Behavior preserved: [yes / exceptions explicitly listed]
- Lines: [before] -> [after]
- Changes:
  - [each behavior-preserving change in one line, e.g. "merged 3 duplicate retry blocks into Invoke-WithRetry"]
- Analyzer: [violations fixed] fixed, [count] remaining (listed above)
- Out of scope findings: [anything noticed but not touched]

Constraints

  • Preserve the script's intended behavior unless the user explicitly asks for a behavior change
  • Prefer editing existing files over creating new ones
  • Remove obsolete code instead of keeping compatibility shims
  • Do not add layers, helper classes, or extra modules unless the current script clearly needs them
  • Keep output, parameters, and side effects predictable
  • Use comments only where the logic would otherwise be hard to follow
  • If a destructive or high risk action is present, preserve or improve safety controls such as ShouldProcess, confirmation, or validation

References

  • shared/skill-standard.md
  • shared/naming-conventions.md
  • Existing repo patterns in the target script's project

Help And Examples

Use this skill when the user already has a PowerShell script and wants it cleaned up, simplified, or standardized.

Minimum useful input:

  • the .ps1 or .psm1 file to refactor
  • the behavior that must stay the same
  • any style constraints such as approved verbs, no comments, or keeping it single file

Example prompts:

text
Refactor this PowerShell script to reduce duplication and make the error handling cleaner, but keep the same output and parameters.
text
Tighten this Intune reporting script. Keep it as one file. Rename functions to approved verbs and remove unnecessary abstraction.
text
Clean up this PowerShell module and standardize the parameter blocks without changing how the commands behave.

Validation Checklist

  • The refactor preserves the intended behavior of the original script
  • Naming, structure, and flow are more consistent than before
  • Unnecessary duplication or dead code has been removed
  • The result uses practical PowerShell conventions instead of generic abstractions
  • Any tests, lint checks, or quick validation steps relevant to the target repo still pass

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Powershell Refactor」では何ができますか?

Refactor existing PowerShell scripts to simplify flow, reduce duplication, standardize naming and structure, and tighten behavior without changing the intended outcome.

TypingMindでPowershell Refactorを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Powershell Refactorはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにPowershell Refactorをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/mickpletcher/AI-Skills/tree/main/claude/skills/powershell-refactorを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Powershell Refactorを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストが合致したときにこのスキルを読み込めます。

Powershell Refactorは何個のAIモデルで使えますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもPowershell Refactorを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Powershell Refactor」は無料ですか?

はい。mickpletcherがGitHubでMITライセンスの下で公開しています。支払いが必要なのは、利用したトークンに対する、ご自身が契約するAIプロバイダーへの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇