agentsclimarketplace

Powershell style guide

Skill chenwei791129/agent-skills/skills/powershell-style-guide

My agent skills

Install
npx -y skills add chenwei791129/agent-skills --skill powershell-style-guide

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Review and write PowerShell code following community style guide and best practices (based on PoshCode/PowerShellPracticeAndStyle). Use when writing new PowerShell scripts, functions, or modules (.ps1, .psm1, .psd1), reviewing PowerShell code for style compliance, refactoring PowerShell code, or any task involving PowerShell scripting where code quality matters.

SKILL.md

4.1 KB, as published. Nobody here has run it

PowerShell Style Guide

Apply the PoshCode PowerShell Practice and Style Guide when writing or reviewing PowerShell code.

Quick Reference - Essential Rules

Formatting

  • OTBS braces: opening { on same line, closing } on own line
  • 4-space indentation (spaces, not tabs)
  • 115 char line limit - use splatting to break long commands
  • No trailing whitespace, no semicolons as line terminators
  • Two blank lines around function/class definitions
  • Single space around operators and after commas

Naming

  • PascalCase everything public: functions, parameters, variables, modules
  • Verb-Noun for functions (approved verbs from Get-Verb)
  • Singular nouns only
  • Full names always: Get-Process -Name Explorer not gps Explorer
  • lowercase for keywords (if, foreach) and operators (-eq, -gt)

Function Structure

function Get-Example {
    <#
        .SYNOPSIS
            Brief description.
        .EXAMPLE
            Get-Example -Name "Test"
            Demonstrates basic usage.
    #>
    [CmdletBinding()]
    [OutputType([string])]
    param(
        # The name to look up
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [string]$Name
    )
    process {
        # Return objects directly, no 'return' keyword
        "Hello, $Name"
    }
}

Key Patterns

  • Always use [CmdletBinding()]
  • Always add [OutputType()]
  • Use SupportsShouldProcess for state-changing commands
  • Use parameter validation attributes ([ValidateSet()], [ValidateRange()], etc.)
  • Avoid return keyword - output objects directly to pipeline
  • Use process {} block for pipeline input, not end {}
  • Strongly type all parameters
  • Use [PSCredential] for credentials, never plain strings

Splatting Over Backticks

# Correct
$Params = @{
    Path        = $FilePath
    Filter      = "*.log"
    Recurse     = $true
    ErrorAction = "Stop"
}
Get-ChildItem @Params

# Avoid backtick continuation
Get-ChildItem -Path $FilePath `
              -Filter "*.log" `
              -Recurse `
              -ErrorAction Stop

Error Handling

try {
    Do-Something -ErrorAction Stop
    Do-More
} catch {
    $err = $_
    Write-Error "Failed: $($err.Exception.Message)"
}

Output Streams

CommandPurpose
Pipeline outputPrimary results (objects)
Write-VerboseStatus/logic details
Write-DebugDebugging info for maintainers
Write-ProgressReal-time progress (ephemeral)
Write-WarningNon-terminating warnings
Write-ErrorNon-terminating errors
Write-HostONLY for Show-/Format- verbs or interactive prompts

Review Checklist

When reviewing PowerShell code, check in priority order:

  1. Correctness: logic bugs, pipeline behavior, error handling
  2. Security: credential handling (PSCredential), input validation, injection risks
  3. CmdletBinding: present with OutputType, ShouldProcess where needed
  4. Naming: Verb-Noun, PascalCase, full names, approved verbs
  5. Formatting: OTBS braces, 4-space indent, line length, spaces around operators
  6. Documentation: comment-based help with Synopsis and Example
  7. Parameters: strongly typed, validation attributes, pipeline support
  8. Output: no Write-Host misuse, single type per command, raw data from tools

References

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.