PSScriptBuilder

Dependency-Aware Script Builder for PowerShell

Build single, deployable scripts from multi-file PowerShell projects — with automatic dependency resolution, topological sorting, and full support for classes, functions, and enums.

Get Started View on GitHub PSGallery — Coming Soon
PowerShell
PS C:\Projects\MyModule>
$cc = New-PSScriptBuilderContentCollector |
    Add-PSScriptBuilderCollector -Type Class `
        -IncludePath "src/Classes" |
    Add-PSScriptBuilderCollector -Type Function `
        -IncludePath "src/Public"

Invoke-PSScriptBuilderBuild `
    -ContentCollector $cc `
    -TemplatePath "build/MyModule.psm1.template" `
    -OutputPath   "build/Output/MyModule.psm1"
PS 5.1 Compatible
Dependency Resolution
Topological Sorting
Template System
Release Management
Build Validation

Why PSScriptBuilder?

Everything you need to go from multi-file project to deployable script

Dependency Resolution

Automatically analyzes class-to-class, function-to-class, and cross-file dependencies using PowerShell AST parsing. Detects circular dependencies early and provides clear error messages before your build fails.

Topological Sorting

Guarantees correct loading order using a proven topological sort algorithm. Base classes always load before derived classes, regardless of file order — no more manual sorting of source files.

Flexible Templates

Define your output structure once using a template with token placeholders. PSScriptBuilder replaces tokens with correctly ordered, resolved content — full control over the final script layout.

Multiple Collectors

Dedicated collectors for Classes, Functions, Enums, Using statements, and raw Files. Each collector is independently configurable with custom include paths, file filters, and collection keys.

Release Management

Built-in SemVer version bumping (Major/Minor/Patch), automatic file updates across your project, build number tracking, and Git information extraction for release metadata.

Build Validation

Catches configuration errors before the build starts. Validates template syntax, placeholder completeness, and collector configuration — then logs every step with full verbose support.

Quick Start

Get up and running in minutes

1

Install and Import the Module

Install PSScriptBuilder from the PowerShell Gallery. Use using module in your build script — it makes PowerShell classes and enums available at parse time.

Install-Module -Name PSScriptBuilder

using module PSScriptBuilder
2

Set the Project Root

Tell PSScriptBuilder where your project lives. All relative paths are resolved from this root.

Set-PSScriptBuilderProjectRoot -Path "C:\Projects\MyModule"
3

Configure Collectors

Create a content collector and attach specialized collectors for each source type. The pipeline syntax keeps configuration readable and composable.

$contentCollector = New-PSScriptBuilderContentCollector |
    Add-PSScriptBuilderCollector -Type Class    -IncludePath "src/Classes" |
    Add-PSScriptBuilderCollector -Type Function -IncludePath "src/Public"
4

Build

Run the build. PSScriptBuilder collects all sources, resolves dependencies, applies topological sorting, and writes the final output file using your template.

Invoke-PSScriptBuilderBuild `
    -ContentCollector $contentCollector `
    -TemplatePath "build/MyModule.psm1.template" `
    -OutputPath   "build/Output/MyModule.psm1"

Typical Workflow

How PSScriptBuilder fits into your PowerShell development pipeline

1
Develop
Your Editor
2
Build
PSScriptBuilder
3
Test
Pester
4
Publish
Publish-Module
Focused on script building — pairs well with psake or InvokeBuild.

Perfect For

Recognize your situation? PSScriptBuilder was built for exactly this.

Standalone Scripts

You write clean, organized source files — but deployment needs a single script. Configure once, then build with a single command. All dependencies resolved, correct order guaranteed.

Object-Oriented PowerShell

Your class hierarchy is growing and the loading order keeps breaking. PSScriptBuilder uses PowerShell's AST to resolve every dependency automatically — no more manual sorting, no more guesswork.

Structured Releases

Bumping versions across multiple files before every release is tedious and error-prone. Define your output structure once with a template, and let PSScriptBuilder handle version bumping, file updates, and Git metadata automatically.

CI/CD Pipelines

Automate your PowerShell build as part of any CI/CD pipeline. PSScriptBuilder produces a deterministic, dependency-resolved output on every run — no manual steps, no surprises.

Frequently Asked Questions

Common questions about PSScriptBuilder

Yes. PSScriptBuilder is fully compatible with both PowerShell 5.1 and PowerShell 7+. The built scripts target PS 5.1 as the lowest common denominator, but the build tooling itself runs on both.

psake and Invoke-Build are general-purpose task runners — they orchestrate your entire build pipeline. PSScriptBuilder solves one specific problem: combining a multi-file PowerShell project into a single, correctly ordered script. They complement each other well — use Invoke-Build to run your pipeline and PSScriptBuilder as one step inside it.

PSScriptBuilder detects circular dependencies during the analysis phase — before any output is written. It throws a clear error that identifies the cycle so you can resolve it in your source code. The build fails fast rather than producing a broken script silently.

No. You point each collector at a directory and it picks up all matching files automatically. You can optionally filter by file pattern or recursion depth, but there is no need to list individual files. New files added to the folder are included on the next build automatically.

Absolutely. PSScriptBuilder produces deterministic output — the same inputs always produce the same script. There are no interactive prompts and all configuration is driven by code. It runs on any Windows agent with PowerShell 5.1+ and requires no dependencies beyond the module itself.