powershell-new-function
Skill24 starsChanged 3 days agoMITView on GitHub
Write a new PowerShell function with its comment-based help and Pester tests, following this repository's PowerShell standards. Use when asked to create, add, or scaffold a PowerShell function or command.
In this repository33 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .claude/rules/powershell-standards/copilot-instructions.mdCopilot instructions
- .github/copilot-instructions.mdCopilot instructions
- powershell-ci-pipelineSkill
- powershell-credential-scanSkill
- powershell-loggingSkill
- powershell-module-helpSkill
- powershell-new-functionSkill
- powershell-new-moduleSkill
- powershell-performance-reviewSkill
- powershell-reviewSkill
- powershell-security-reviewSkill
- powershell-write-testsSkill
- powershell-ci-pipelineSkill
- powershell-credential-scanSkill
- powershell-loggingSkill
- powershell-module-helpSkill
- powershell-new-functionSkill
- powershell-new-moduleSkill
- powershell-performance-reviewSkill
- powershell-reviewSkill
- powershell-security-reviewSkill
- powershell-write-testsSkill
- powershell-ci-pipelineSkill
- powershell-credential-scanSkill
- powershell-loggingSkill
- powershell-module-helpSkill
- powershell-new-moduleSkill
- powershell-performance-reviewSkill
- powershell-reviewSkill
- powershell-security-reviewSkill
- powershell-write-testsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Read these before writing code, unless they are already loaded:
- Very specific: line 26
Write the function in the shape of the function template: help first, [CmdletBinding()], [OutputType()], typed and validated parameters, a …
- Very specific: line 31
If the function changes state, add SupportsShouldProcess and guard each change with $PSCmdlet.ShouldProcess().
- Very specific: line 33
Write the tests following .github/instructions/powershell-pester.instructions.md, in Tests/Unit/<Name>.Tests.ps1 (MOD-01) or beside the …
- Very specific: line 36
Run PSScriptAnalyzer on the new files, with -Settings ./PSScriptAnalyzerSettings.psd1 when that file exists, and run the tests.
≈ “Common” is an estimate: at least 1 in 5 of the 383,637 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.
Files
Write a new PowerShell function
Read these before writing code, unless they are already loaded:
.github/copilot-instructions.md, orAGENTS.mdif the repository has no such file (the core rules and the function template).github/instructions/powershell-functions.instructions.md.github/instructions/powershell-error-handling.instructions.md.github/instructions/powershell-help.instructions.md
Steps
- Find the target version. Read the
#requires -Versionlines and the nearest module manifest. If the project declares nothing and it is not clear which target applies, ask. If you cannot ask, target PowerShell 7.6 and say that you assumed it. - Choose the name. Use a verb that
Get-Verblists and a singular noun. Search the repository for an existing function with that name or purpose before creating a new one. - Decide where the file goes. In a module, an exported function goes in
Public/<Name>.ps1and its name is added toFunctionsToExportin the manifest; an internal one goes inPrivate/<Name>.ps1. Outside a module, put it where the user asked. - Write the function in the shape of the function template: help first,
[CmdletBinding()],[OutputType()], typed and validated parameters, aprocessblock for pipeline input,tryand$PSCmdlet.ThrowTerminatingError()for a failure that ends the function,$PSCmdlet.WriteError()for a failure of one item, and objects written to the pipeline as they are produced. - If the function changes state, add
SupportsShouldProcessand guard each change with$PSCmdlet.ShouldProcess(). If it only reads, do not. - Write the tests following
.github/instructions/powershell-pester.instructions.md, inTests/Unit/<Name>.Tests.ps1(MOD-01) or beside the tests the project already has. Cover each parameter set, the documented output, each validation failure, and each error path. - Run PSScriptAnalyzer on the new files, with
-Settings ./PSScriptAnalyzerSettings.psd1when that file exists, and run the tests. Fix what they report.
Report
Say which files you created or changed, which PowerShell version you targeted and why, what you ran and what it reported, and anything you could not verify. Ask instead of guessing when the purpose, the inputs, or the output of the function is unclear.
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
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.

