Hand-written PSD1 files often have inconsistent indentation, key alignment, and value formatting. A Format-PowerShellDataFile function normalizes the text without changing semantics — equivalent to ConvertFrom-PowerShellDataFile | ConvertTo-PowerShellDataFile but expressed as a single ergonomic call.
Sister modules already follow this pattern: Format-Json and Format-Hashtable. PSD1 is the natural place to land canonical-form module manifests in CI workflows.
Request
Desired capability
Get-Content module.psd1 -Raw | Format-PowerShellDataFile
Format-PowerShellDataFile -Path module.psd1 -Indent 4
Parameters
| Parameter |
Description |
-InputObject |
String to format (ValueFromPipeline, default set) |
-Path |
File path to read and format |
-LiteralPath |
Literal file path |
-Indent |
Spaces per nesting level (default: 4 — PSD1 convention) |
-AlignValues |
Pad keys with spaces so values align in columns within the same hashtable (default: $false) |
Acceptance criteria
Format-PowerShellDataFile $s produces canonical PSD1 for $s
- Idempotent:
Format-PowerShellDataFile (Format-PowerShellDataFile $s) equals Format-PowerShellDataFile $s
- Output round-trips:
ConvertFrom-PowerShellDataFile produces equivalent objects from input and formatted output
- Output passes
Test-ModuleManifest when the input is a valid module manifest
-Indent controls spacing between nested table levels
-AlignValues produces aligned-column output (matches the New-ModuleManifest style)
Technical decisions
Implementation: Parses input with ConvertFrom-PowerShellDataFile and re-emits with ConvertTo-PowerShellDataFile using the requested indentation and alignment. Reuses existing logic — no new parser or emitter.
Function placement: src/functions/public/Format-PowerShellDataFile.ps1.
Parameter sets: InputObject (default, pipeline) and Path / LiteralPath for file input.
Indent default: 4 spaces — matches the convention used by New-ModuleManifest output.
Alias: Format-Psd1.
Implementation plan
Related
- ConvertFrom/ConvertTo-PowerShellDataFile (prerequisite — separate issue)
Hand-written PSD1 files often have inconsistent indentation, key alignment, and value formatting. A
Format-PowerShellDataFilefunction normalizes the text without changing semantics — equivalent toConvertFrom-PowerShellDataFile | ConvertTo-PowerShellDataFilebut expressed as a single ergonomic call.Sister modules already follow this pattern:
Format-JsonandFormat-Hashtable. PSD1 is the natural place to land canonical-form module manifests in CI workflows.Request
Desired capability
Parameters
-InputObjectValueFromPipeline, default set)-Path-LiteralPath-Indent-AlignValues$false)Acceptance criteria
Format-PowerShellDataFile $sproduces canonical PSD1 for$sFormat-PowerShellDataFile (Format-PowerShellDataFile $s)equalsFormat-PowerShellDataFile $sConvertFrom-PowerShellDataFileproduces equivalent objects from input and formatted outputTest-ModuleManifestwhen the input is a valid module manifest-Indentcontrols spacing between nested table levels-AlignValuesproduces aligned-column output (matches theNew-ModuleManifeststyle)Technical decisions
Implementation: Parses input with
ConvertFrom-PowerShellDataFileand re-emits withConvertTo-PowerShellDataFileusing the requested indentation and alignment. Reuses existing logic — no new parser or emitter.Function placement:
src/functions/public/Format-PowerShellDataFile.ps1.Parameter sets:
InputObject(default, pipeline) andPath/LiteralPathfor file input.Indent default: 4 spaces — matches the convention used by
New-ModuleManifestoutput.Alias:
Format-Psd1.Implementation plan
Format-PowerShellDataFileinsrc/functions/public/Format-PowerShellDataFile.ps1withFormat-Psd1alias-Indent,-AlignValues, idempotent round-trip, manifest validation after formatexamples/General.ps1Related