PowerShell Module Scaffolder Skill
Summary: Create a skeleton PowerShell module (.psm1/.psd1), sample function, and Pester test harness.
Usage:
- •Inputs: module name, functions list
- •Outputs: module folder,
README.md,tests/with Pester examples
Requirements:
- •PowerShell 7.x available for local development and CI
- •Pester 5.x for unit tests (
Invoke-Pester) - •
PSScriptAnalyzerconfigured with a repository baseline (recommended)
Steps:
- •Enforce approved verb-noun names and module layout (see verb-validation micro-procedure below).
- •Add
PSScriptAnalyzersettings and sample Pester tests.
Example scaffold (expected output):
code
MyModule/ ├── MyModule.psd1 ├── MyModule.psm1 ├── Public │ └── Get-MyThing.ps1 ├── README.md ├── tests │ └── Get-MyThing.Tests.ps1 └── .vscode/ (optional dev settings)
Example function (Public/Get-MyThing.ps1):
powershell
function Get-MyThing {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Name
)
process {
return @{ Name = $Name; Created = (Get-Date) }
}
}
Export-ModuleMember -Function Get-MyThing
Example Pester test (tests/Get-MyThing.Tests.ps1):
powershell
Describe 'Get-MyThing' {
It 'returns an object with Name and Created' {
$result = Get-MyThing -Name 'Test'
$result | Should -Not -BeNullOrEmpty
$result.Name | Should -Be 'Test'
}
}
NEVER / Anti-Patterns:
- •NEVER commit secrets or credentials to the scaffolded module. Use Key Vault or secure pipelines for secrets.
- •NEVER disable
PSScriptAnalyzerrules globally. If a rule is noisy, scope an exception and document why it was relaxed. - •NEVER skip tests in CI. Scaffolding should include a baseline test that runs in CI.
- •NEVER use unapproved verbs. Prefer Microsoft-approved verbs (see verb-validation micro-procedure).
Verb-validation micro-procedure (how to verify approved verbs):
- •Check the requested verb against the Microsoft Approved Verbs list: https://learn.microsoft.com/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell
- •If the verb is not on the list, suggest an alternative approved verb and explain mapping (e.g.,
Get→ read-like operations,New→ create-like operations). - •For ambiguous cases, prefer broader verbs (
Get,Set,Remove,Test,Invoke) and document the justification inREADME.md.
Integration Test Checklist (how to validate the scaffolder output):
- •Test 1: Scaffold a module
MyModulewith functionGet-MyThingand verify the file tree exists as in the example scaffold. - •Test 2: Run
Import-ModuleandInvoke-Pesterlocally to confirm tests pass. - •Test 3: Run
Invoke-ScriptAnalyzerwith the repo baseline and ensure no new high-severity issues are introduced.
Implementation notes for the Agent:
- •Ask for module name, list of functions, and preferred verbs.
- •Validate verbs (use micro-procedure) and prompt for replacements if needed.
- •Generate files, add minimal
README.mdandPSScriptAnalyzerbaseline, and include example tests. - •Return a checklist the user can run locally:
pwsh -Command "Import-Module .; Invoke-Pester; Invoke-ScriptAnalyzer -Path .".