Skip to content

andmigque/PSTemplate

Repository files navigation

🪫 PSTemplate

A Powershell GitHub template repository. It comes wired with Pester, PSScriptAnalyzer, and Invoke-Build for test, lint, and build automation.

Quick Start

Import the module and call the sample public function:

# git clone this repo
# or sign in and click use this template
Import-Module .\PSTemplate.psd1
Write-PublicTest
PSTemplate repo is correctly configured

Run the default build:

Invoke-Build
Running tests.
PSTemplate repo is correctly configured
hello
[+] PSTemplate\Tests\Write-PublicTest.Tests.ps1 1.41s (347ms|787ms)
Tests completed in 1.52s
Tests Passed: 6, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
Processing code coverage result.
Covered 50% / 75%. 4 analyzed Commands in 2 Files.
Done /test_pester 00:00:03.6772325

Results and coverage land in Generated/ as PesterTests.xml and PesterCodeCoverage.xml.

🔙Background

This template repository comes wired with all the DevOps tooling you need for your new powershell project.

Drop your functions into Public/ and Private/, drop their tests into Tests/, and the existing wiring carries them — no loader edits, no manifest bookkeeping per function.

  • Public/ — exported functions, one per file, file name matches the function. Ships with Write-PublicTest.ps1.
  • Private/ — internal helpers, dot-sourced but not exported. Ships with Write-PrivateTest.ps1.
  • Tests/ — Pester specs (*.Tests.ps1). Ships with Write-PublicTest.Tests.ps1.
  • Docs/ — bundled PowerShell authoring references: cmdlet design rules (Docs/Rules/), Pester help (Docs/Pester/), path cmdlets (Docs/Path/), and worked examples (Docs/Examples/).
  • PSTemplate.psm1 — loader: dot-sources Private/ then Public/, exports the public surface.
  • PSTemplate.psd1 — module manifest.
  • PSTemplate.Build.ps1 — InvokeBuild tasks.
  • PSTemplate.ScriptAnalyzer.psd1 — PSScriptAnalyzer rule profile.

How To

Add a public function

  1. Create Public/Verb-Noun.ps1 with a single advanced function named Verb-Noun.
  2. Create Tests/Verb-Noun.Tests.ps1 next to the existing sample spec.
  3. Re-import: Import-Module ./PSTemplate.psd1 -Force. The loader exports it automatically — no manifest edit required.

Build tasks

The build runs on InvokeBuild. Install it once with Install-Module InvokeBuild, then:

# Pester tests + code coverage -> Generated/
Invoke-Build test_pester -File ./PSTemplate.Build.ps1

# PSScriptAnalyzer report -> Generated/ScriptAnalyzer.txt
Invoke-Build test_ps_script_analyzer -File ./PSTemplate.Build.ps1

License

MIT. See LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors