Getting Started with PowerShellBuild
This guide walks through adding PowerShellBuild to a PowerShell module project from scratch. By the end you will have a working build pipeline that cleans, stages, analyzes, tests, and packages your module.
Prerequisites
- PowerShell 5.1 or PowerShell 7+
- psake >= 5.0.4
- PowerShellBuild >= 0.8.2
These versions match PowerShellBuild 0.8.2. Check the current module manifest when selecting a newer release.
Install both modules from the PowerShell Gallery:
Install-Module -Name psake -Repository PSGallery
Install-Module -Name PowerShellBuild -Repository PSGallery
Expected Directory Structure
PowerShellBuild expects a conventional PowerShell module layout. The defaults work with the following structure (all paths are configurable — see Configuration):
MyModule/
├── src/
│ ├── MyModule.psd1 # Module manifest
│ ├── MyModule.psm1 # Root module file
│ ├── Public/ # Exported functions
│ │ └── Get-Thing.ps1
│ └── Private/ # Internal functions
│ └── Invoke-Helper.ps1
├── tests/
│ └── MyModule.Tests.ps1 # Pester tests
├── docs/ # PlatyPS markdown (generated)
├── build/ # Output directory (generated)
├── psakeFile.ps1 # Your build task file
├── build.ps1 # Build bootstrap script
└── requirements.psd1 # Module dependencies
Minimal Setup
1. Create psakeFile.ps1
The simplest possible build file just references the Build task from PowerShellBuild:
properties {
$PSBPreference.Build.OutDir = "$PSScriptRoot/build"
$PSBPreference.General.SrcRootDir = "$PSScriptRoot/src"
}
task default -depends Build
task Build -FromModule PowerShellBuild -RequiredVersion '0.8.2'
That is all you need. psake finds PowerShellBuild, dot-sources its module-root psakeFile.ps1, and registers the provider tasks in the current build context. Running Build then executes its reachable dependency chain:
Init → Clean → StageFiles → GenerateMarkdown → GenerateMAML → BuildHelp → Build