agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/languages/powershell/SKILL.md

powershell

Skill15 starsChanged 42 days agoMITView on GitHub

Expert PowerShell assistance covering cmdlet pipelines, object manipulation, modules, and cross-platform scripting. Use when automating Windows/Azure administration, creating scripts, or managing DevOps tasks.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

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

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

    Follow Standard Approved Verb-Noun Naming: Use approved verbs (Get-, Set-, New-, Remove-, Invoke-).

    line 114
  2. Distinctive:

    Use PowerShell 7+ (pwsh): Standardize on cross-platform PowerShell 7+.

    line 115
  3. Very specific:

    Add [CmdletBinding()] to Custom Functions: Gain automatic support for -Verbose, -Debug, and -ErrorAction.

    line 116
  4. Distinctive:

    Use PSScriptAnalyzer in CI: Run automated static analysis to catch security flaws and code quality issues.

    line 117
  5. Very specific:

    Use command aliases in production scripts: Avoid ls, cat, curl, and select.

    line 121

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “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

A task-based command-line shell and scripting language built on .NET.

When to Use

  • Windows Enterprise & Active Directory Automation: Managing Windows Server, Azure Active Directory, Hyper-V, and Exchange estates.
  • Cross-Platform DevOps Automation (PS 7+): Writing cross-platform administration scripts executing identically on Windows, Linux, and macOS.
  • Azure Infrastructure Orchestration (Az Module): Automating cloud resource deployment, subscriptions, and security compliance policies.
  • Object-Oriented Pipeline Scripting: Passing structured .NET objects between commands rather than raw unstructured text streams.

Quick Start

$name = "World"
Write-Host "Hello, $name!"

$processes = Get-Process | Where-Object { $_.CPU -gt 10 }
foreach ($p in $processes) {
    Write-Output $p.Name
}

Core Concepts

Object-Oriented Pipeline Architecture

Commands pass strongly-typed .NET objects rather than plain text; downstream commands access properties directly:

# Passes rich Process objects through the pipeline
Get-Process |
  Where-Object WorkingSet64 -GT 500MB |
  Sort-Object WorkingSet64 -Descending |
  Select-Object -First 5 -Property Name, Id, @{Name="RAM_MB"; Expression={$_.WorkingSet64 / 1MB}}

Advanced Parameter Validation & Cmdlet Binding

Enforces parameter types, mandatory attributes, and validation rules:

function Invoke-Deployment {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory = $true)]
        [ValidateSet("Staging", "Production")]
        [string]$Environment,

        [Parameter(Mandatory = $true)]
        [ValidatePattern('^v\d+\.\d+\.\d+$')]
        [string]$Version
    )

    if ($PSCmdlet.ShouldProcess($Environment, "Deploying release $Version")) {
        Write-Host "Deploying $Version to $Environment..." -ForegroundColor Green
    }
}

Error Action Preferences and Try/Catch

Handles terminating and non-terminating errors cleanly:

$ErrorActionPreference = "Stop" # Treat all errors as terminating

try {
    Invoke-RestMethod -Uri "https://api.internal.corp/status" -Method GET -TimeoutSec 5
} catch [System.Net.WebException] {
    Write-Warning "Network connection failed: $($_.Exception.Message)"
} catch {
    Write-Error "Unexpected fatal error: $_"
}

Common Patterns

Advanced Pipeline Function with ShouldProcess Support

Problem: Automating destructive infrastructure changes without dry-run safety mechanisms.

Solution: Build advanced functions supporting -WhatIf and pipeline input:

function Remove-StaleLogs {
    [CmdletBinding(SupportsShouldProcess = $true)]
    param(
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
        [string]$Path,
        [int]$DaysOld = 30
    )
    process {
        $cutoff = (Get-Date).AddDays(-$DaysOld)
        Get-ChildItem -Path $Path -Filter *.log | Where-Object { $_.LastWriteTime -lt $cutoff } | ForEach-Object {
            if ($PSCmdlet.ShouldProcess($_.FullName, "Delete stale log")) {
                Remove-Item $_.FullName -Force
            }
        }
    }
}

Best Practices

Do:

  • Follow Standard Approved Verb-Noun Naming: Use approved verbs (Get-, Set-, New-, Remove-, Invoke-).
  • Use PowerShell 7+ (pwsh): Standardize on cross-platform PowerShell 7+; avoid legacy Windows PowerShell 5.1.
  • Add [CmdletBinding()] to Custom Functions: Gain automatic support for -Verbose, -Debug, and -ErrorAction.
  • Use PSScriptAnalyzer in CI: Run automated static analysis to catch security flaws and code quality issues.

Don't:

  • Use command aliases in production scripts: Avoid ls, cat, curl, and select; use full cmdlet names (Get-ChildItem).
  • Parse text output with regex when objects exist: Access object properties directly ($proc.Id) rather than parsing text.
  • Store plaintext passwords: Use PSCredential with SecretManagement or Azure Key Vault.

Troubleshooting

ErrorCauseSolution
execution of scripts is disabled on this systemExecution policy restricts running unsigned PowerShell scripts.Run Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned.
The term '...' is not recognized as the name of a cmdletModule not installed, missing in $env:PSModulePath, or typo.Install module with Install-Module -Name <Name>.
Cannot bind argument to parameter because it is nullParameter defined with [Parameter(Mandatory)] received null input.Verify pipeline output or provide default parameter value.

References

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.