agentleFS
CsHengCsHeng/agent-skills/skills/powershell-guidelines/SKILL.md

powershell-guidelines

Skill3 starsChanged 8 days agoMITView on GitHub

Apply PowerShell 7 policy as a conditional overlay when writing or reviewing PowerShell scripts, modules, and manifests: pwsh, PSScriptAnalyzer, strict mode, approved verbs, and cross-platform scripting. Code that must stay compatible with Windows PowerShell 5.1 gets no overlay from this policy, which also does not authorize upgrading it.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 0 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read-only review checks: references/review-checklist.md

    line 15
  2. Very specific:

    Start every script with #Requires -Version 7.0, adding #Requires -Modules for external module dependencies.

    line 21
  3. Very specific:

    Follow it with Set-StrictMode -Version Latest and $ErrorActionPreference = 'Stop'.

    line 22
  4. Very specific:

    Use PascalCase for functions, parameters and script-scoped variables, and $camelCase for locals.

    line 27
  5. Very specific:

    Write full cmdlet names in scripts (Get-ChildItem, not ls).

    line 29
  6. Very specific:

    Use [CmdletBinding()] for advanced functions and [Parameter(Mandatory)] for required inputs.

    line 39
  7. Very specific:

    Use $PSCmdlet.ThrowTerminatingError() in advanced functions.

    line 46
  8. Very specific:

    Check $LASTEXITCODE after every native command.

    line 47
  9. Very specific:

    Run the parser check and Invoke-ScriptAnalyzer (Warning and Error severity) from references/operational-checks.md.

    line 52

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

PowerShell Guidelines

Apply PowerShell 7 standards for safe, portable, auditable automation to .ps1, .psm1 and .psd1 files, including scripts authored on macOS for Windows execution, and to their review and syntax audit. Language selection reads references/language-selection.md in skills-routing; ad hoc tool choice reads references/tool-selection.md there.

Progressive Disclosure

  • Parser, analyzer and approved-verb commands: references/operational-checks.md
  • Authoring on macOS for Windows execution, or a case-sensitivity, line-ending or native-command portability question: references/macos-notes.md
  • Writing an advanced function with error records, or checking a native command's exit code: references/error-handling-examples.md
  • Read-only review checks: references/review-checklist.md

Rules

Script Header

  • Start every script with #Requires -Version 7.0, adding #Requires -Modules for external module dependencies.
  • Follow it with Set-StrictMode -Version Latest and $ErrorActionPreference = 'Stop'. Use 'SilentlyContinue' only inside a documented exception-handling block.

Naming

  • Name functions Verb-Noun with an approved verb (Get-Verb lists them).
  • Use PascalCase for functions, parameters and script-scoped variables, and $camelCase for locals.
  • Name script files in PascalCase: Get-UserReport.ps1.
  • Write full cmdlet names in scripts (Get-ChildItem, not ls).
  • Pass data through parameters and return values.

Paths

  • Build every path with Join-Path and $PSScriptRoot, and guard any platform-specific literal (such as C:\...) with a platform check.
  • A single [System.IO.Path]::Combine() call may join three or more trusted literal segments in one expression, when no later segment is rooted (a rooted segment discards the earlier path).

Inputs And Security

  • Use [CmdletBinding()] for advanced functions and [Parameter(Mandatory)] for required inputs. Choose parameter types and validation attributes ([ValidateSet()], [ValidatePattern()], [ValidateRange()]) for the actual input constraints, and reject unexpected values early.
  • Pass untrusted input as parameters or typed values.
  • Supply secrets, credentials and API keys through the environment or a secret mechanism, and accept passwords as [SecureString] or credential objects.

Errors

  • Let failures propagate to the owning boundary. Add try/catch where recovery or context is needed, and finally where cleanup must run on success and failure. Include the operation attempted and relevant values in error messages.
  • Use $PSCmdlet.ThrowTerminatingError() in advanced functions.
  • Check $LASTEXITCODE after every native command.
  • For generic error-handling patterns, see error-patterns.

Checks

Run the parser check and Invoke-ScriptAnalyzer (Warning and Error severity) from references/operational-checks.md; the parser check exits non-zero when Parser::ParseFile reports diagnostics. Test scripts with pwsh on macOS before deploying to Windows.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.