Skip to content

Test-PSScriptBuilderTemplate

Validates a PSScriptBuilder template file without performing a build.

Description

Runs the same collection and dependency analysis a real build would — so it sees the same cross-dependencies — then reports whether the template is valid, without writing any output. Returns a plain $true/$false; for the specific errors when it's $false, or a full report of which placeholders are missing or unknown, use Get-PSScriptBuilderTemplateAnalysis instead — or add -Verbose here to see the same validation detail logged as it runs.

See Placeholder Rules and Validation Modes for what's actually checked, and Validation Error Reference for what each failure means and how to fix it.

Parameters

Name Type Description
-ContentCollector PSScriptBuilderContentCollector Required. The collector configuration to validate against. Accepts pipeline input, enabling fluent chaining from Add-PSScriptBuilderCollector.
-TemplatePath string Required. Path to the template file to validate.
-OrderedComponentsKey string The combined-components placeholder key, for Ordered/Hybrid Mode templates. Default: "ORDERED_COMPONENTS".

Examples

Validate before building

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

if (Test-PSScriptBuilderTemplate -ContentCollector $contentCollector -TemplatePath "build\Templates\MyProject.ps1.template") {
    Invoke-PSScriptBuilderBuild -ContentCollector $contentCollector `
        -TemplatePath "build\Templates\MyProject.ps1.template" `
        -OutputPath   "build\Output\MyProject.ps1"
}

Validate with a custom combined-components key

Test-PSScriptBuilderTemplate -ContentCollector $contentCollector `
    -TemplatePath "template.psm1" `
    -OrderedComponentsKey "ALL_COMPONENTS"

Output

Returns $true if the template is valid, $false otherwise. Only unexpected errors (e.g. a missing template file) are terminating — a failed validation is a normal $false result, not an error.

See Also