PowerShell ships Import-PowerShellDataFile but has no built-in Export-PowerShellDataFile. Modules that need to persist a hashtable to disk in PSD1 form — module manifests, configuration snapshots, generated localized data files — currently have to compose the file by hand string-by-string, or call New-ModuleManifest (which is manifest-specific and inflexible).
This issue adds the missing Export-PowerShellDataFile. There is intentionally no Import-PowerShellDataFile here — the built-in already covers that surface; the module re-exports the built-in (or omits it entirely).
Request
Desired capability
$config | Export-PowerShellDataFile -Path settings.psd1
$manifest | Export-PowerShellDataFile -Path module.psd1 -NoClobber
Standard parameters
| Parameter |
Description |
-Path |
File path (position 0, default parameter set) |
-LiteralPath |
Literal path (no wildcard expansion) |
-InputObject |
Hashtable to export (ValueFromPipeline, mandatory) |
-Encoding |
Default utf8NoBOM |
-NoClobber |
Fail if target exists |
-Force |
Overwrite read-only files |
-Indent |
Spaces per nesting level (default: 4) |
All ConvertTo-PowerShellDataFile parameters pass through.
Acceptance criteria
$h | Export-PowerShellDataFile -Path f.psd1 produces a file readable by the built-in Import-PowerShellDataFile
- Output round-trips:
Import-PowerShellDataFile $f returns an equivalent hashtable
-NoClobber, -Force, -Encoding, -LiteralPath behave as in Export-Csv
ShouldProcess support (-WhatIf, -Confirm)
- The generated file passes
Test-ModuleManifest when the input represents a valid module manifest
Technical decisions
Architecture: Thin wrapper around ConvertTo-PowerShellDataFile (tracked separately). Adds only file I/O and the standard file-cmdlet parameters.
Function placement: src/functions/public/Export-PowerShellDataFile.ps1.
Parameter sets: Path (default, position 0) and LiteralPath, mirroring Export-Csv.
No Import-PowerShellDataFile in this module: The built-in already exists. Re-implementing or shadowing it adds risk without benefit. If the module ever needs to extend the built-in (e.g., string parsing), that lives under ConvertFrom-PowerShellDataFile rather than a competing Import- function.
Alias: Export-Psd1.
Encoding default: UTF-8 without BOM — matches PowerShell 7+ default for Set-Content.
Implementation plan
Related
- ConvertFrom/ConvertTo-PowerShellDataFile (prerequisite — separate issue)
PowerShell ships
Import-PowerShellDataFilebut has no built-inExport-PowerShellDataFile. Modules that need to persist a hashtable to disk in PSD1 form — module manifests, configuration snapshots, generated localized data files — currently have to compose the file by hand string-by-string, or callNew-ModuleManifest(which is manifest-specific and inflexible).This issue adds the missing
Export-PowerShellDataFile. There is intentionally noImport-PowerShellDataFilehere — the built-in already covers that surface; the module re-exports the built-in (or omits it entirely).Request
Desired capability
Standard parameters
-Path-LiteralPath-InputObjectValueFromPipeline, mandatory)-Encodingutf8NoBOM-NoClobber-Force-IndentAll
ConvertTo-PowerShellDataFileparameters pass through.Acceptance criteria
$h | Export-PowerShellDataFile -Path f.psd1produces a file readable by the built-inImport-PowerShellDataFileImport-PowerShellDataFile $freturns an equivalent hashtable-NoClobber,-Force,-Encoding,-LiteralPathbehave as inExport-CsvShouldProcesssupport (-WhatIf,-Confirm)Test-ModuleManifestwhen the input represents a valid module manifestTechnical decisions
Architecture: Thin wrapper around
ConvertTo-PowerShellDataFile(tracked separately). Adds only file I/O and the standard file-cmdlet parameters.Function placement:
src/functions/public/Export-PowerShellDataFile.ps1.Parameter sets:
Path(default, position 0) andLiteralPath, mirroringExport-Csv.No
Import-PowerShellDataFilein this module: The built-in already exists. Re-implementing or shadowing it adds risk without benefit. If the module ever needs to extend the built-in (e.g., string parsing), that lives underConvertFrom-PowerShellDataFilerather than a competingImport-function.Alias:
Export-Psd1.Encoding default: UTF-8 without BOM — matches PowerShell 7+ default for
Set-Content.Implementation plan
Export-PowerShellDataFileinsrc/functions/public/Export-PowerShellDataFile.ps1withExport-Psd1aliastests/Export-PowerShellDataFile.Tests.ps1— basic write,-NoClobber,-Force,-Encoding,-WhatIf, pipeline input, round-trip via built-inImport-PowerShellDataFileTest-ModuleManifest)examples/General.ps1and READMERelated