| [ Web Proxy ] |
| Viewing: https://docs.psscriptbuilder.com/cmdlets/../../guides/../../cmdlets/Test-PSScriptBuilderTemplate/ | [Back] [Original] |
Validates a PSScriptBuilder template file without performing a build.
Test-PSScriptBuilderTemplate [-ContentCollector] <PSScriptBuilderContentCollector> [-TemplatePath] <String>
[[-OrderedComponentsKey] <String>] [<CommonParameters>]
The Test-PSScriptBuilderTemplate cmdlet validates template content against the current collector configuration. It checks:
In Ordered and Hybrid mode (when the ordered components placeholder is used):
In Free Mode (when no cross-dependencies and no ordered components placeholder in template):
This cmdlet is useful for:
$isValid = New-PSScriptBuilderContentCollector |
Add-PSScriptBuilderCollector -Type Class -IncludePath "src\Classes" |
Add-PSScriptBuilderCollector -Type Function -IncludePath "src\Public" |
Test-PSScriptBuilderTemplate -TemplatePath "template.psm1"
if ($isValid) {
Write-Host "Template is valid" -ForegroundColor Green
}
Fluent pipeline validation with conditional output.
$cc = New-PSScriptBuilderContentCollector |
Add-PSScriptBuilderCollector -Type Class -IncludePath "src\Classes" |
Add-PSScriptBuilderCollector -Type Function -IncludePath "src\Public"
if (Test-PSScriptBuilderTemplate -ContentCollector $cc -TemplatePath "template.psm1" -Verbose) {
Invoke-PSScriptBuilderBuild -ContentCollector $cc `
-TemplatePath "template.psm1" `
-OutputPath "build\output\MyModule.psm1"
} else {
Write-Warning "Template validation failed. Build skipped."
}
Pre-flight validation before build. Use -Verbose to see detailed validation steps.
$cc = New-PSScriptBuilderContentCollector |
Add-PSScriptBuilderCollector -Type Using -IncludePath "src" |
Add-PSScriptBuilderCollector -Type Enum -IncludePath "src\Enums" |
Add-PSScriptBuilderCollector -Type Class -IncludePath "src\Classes" |
Add-PSScriptBuilderCollector -Type Function -IncludePath "src\Public"
Test-PSScriptBuilderTemplate -ContentCollector $cc `
-TemplatePath "template.psm1" `
-OrderedComponentsKey "ALL_COMPONENTS"
Validates template with custom placeholder key for ordered components.
The PSScriptBuilderContentCollector instance containing all configured collectors. Can be passed via pipeline from New-PSScriptBuilderContentCollector or Add-PSScriptBuilderCollector.
Type: PSScriptBuilderContentCollector
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
Path to the template file to validate. Supports both absolute paths and paths relative to the project root (as set via Set-PSScriptBuilderProjectRoot).
The path is resolved using FileSystemHelper.GetProjectRootedPath(), which means:
Example paths:
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
The placeholder key used in the template for dependency-ordered components. Default is "ORDERED_COMPONENTS" (resulting in {{ORDERED_COMPONENTS}} in template).
This is used in Ordered and Hybrid mode where all components must be merged in dependency order.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: ORDERED_COMPONENTS
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
The cmdlet performs dependency analysis to determine the validation mode:
Validation is comprehensive and catches common template issues early:
Template validation failures return $false (not an error):
This is a lightweight validation-only operation. No files are modified and no output is generated. For detailed analysis results, use Get-PSScriptBuilderTemplateAnalysis.
All validation details are logged by the worker classes when -Verbose is specified:
| Web Proxy Viewer | New URL | Original Page |