PowerShell ships Import-PowerShellDataFile for safely reading .psd1 files from disk, but it has no string-based equivalent. Scripts that receive PSD1 content from non-file sources (HTTP responses, Git blobs, embedded strings, multi-document streams) currently have to write the content to a temporary file before parsing — or fall back to Invoke-Expression, which executes arbitrary code.
There is also no built-in way to serialize a hashtable back into PSD1 syntax. The Hashtable module's Format-Hashtable is close, but it produces general PowerShell hashtable literals rather than canonical PSD1 (which restricts allowed value types to a documented subset).
This is the foundational issue for the module — Import-, Export-, Test-, and Format- all build on these two functions.
Request
Desired capability
$data=ConvertFrom-PowerShellDataFile$psd1Content$data=$psd1Content|ConvertFrom-PowerShellDataFile$psd1=ConvertTo-PowerShellDataFile$hashtable$psd1=$hashtable|ConvertTo-PowerShellDataFile-Indent 4
ConvertFrom-PowerShellDataFile parameters
| Parameter | Description |
|---|
-InputObject | PSD1 string content (ValueFromPipeline, default set, position 0) |
-SkipLimitCheck | Bypass the 500-key / 5000-AST-node safety limits (matches the built-in Import-PowerShellDataFile) |
Returns [hashtable] — same shape as the built-in Import-PowerShellDataFile.
ConvertTo-PowerShellDataFile parameters
| Parameter | Description |
|---|
-InputObject | Hashtable, ordered dictionary, or PSCustomObject (ValueFromPipeline, position 0) |
-Depth | Maximum nesting depth (default: 1024) |
-Indent | Spaces per nesting level (default: 4 — PSD1 convention) |
-EnumsAsStrings | Render enum values as their string names |
Returns [string].
Acceptance criteria
ConvertFrom-PowerShellDataFile parses PSD1 content using the PowerShell AST (no Invoke-Expression, same safety as Import-PowerShellDataFile)- Returns equivalent output to
Import-PowerShellDataFile for the same content ConvertTo-PowerShellDataFile produces output that round-trips through ConvertFrom-PowerShellDataFile- Only PSD1-allowed types are emitted: hashtables, arrays, strings, numbers, booleans,
null, [datetime], [guid], [char], [scriptblock] (per the documented subset) - Throws a clear error when serializing a type that PSD1 does not allow (e.g.,
[pscustomobject] instances should be converted to hashtable first or rejected with guidance) - Pipeline input works for both functions
Technical decisions
Parser approach: Use [System.Management.Automation.Language.Parser]::ParseInput() and walk the resulting AST. This matches how the built-in Import-PowerShellDataFile validates safety. No Invoke-Expression, no iex, no shelling out.
Allowed types: Mirror the documented PSD1 subset. Reject other types at serialization time with a clear error.
Function placement:src/functions/public/ConvertFrom-PowerShellDataFile.ps1 and src/functions/public/ConvertTo-PowerShellDataFile.ps1.
Aliases:ConvertFrom-Psd1 / ConvertTo-Psd1 for shorter common usage.
Output types:[hashtable] for ConvertFrom, [string] for ConvertTo.
Indent default: 4 spaces — matches the PowerShell module manifest convention generated by New-ModuleManifest.
Relationship to existing functions: Replaces the placeholder Set-PSModuleTest function in the repo. Cleanup is part of this issue.
Breaking changes: None — there are no real public functions today.
Implementation plan
Core functions
Tests
Cleanup
PowerShell ships
Import-PowerShellDataFilefor safely reading.psd1files from disk, but it has no string-based equivalent. Scripts that receive PSD1 content from non-file sources (HTTP responses, Git blobs, embedded strings, multi-document streams) currently have to write the content to a temporary file before parsing — or fall back toInvoke-Expression, which executes arbitrary code.There is also no built-in way to serialize a hashtable back into PSD1 syntax. The Hashtable module's
Format-Hashtableis close, but it produces general PowerShell hashtable literals rather than canonical PSD1 (which restricts allowed value types to a documented subset).This is the foundational issue for the module —
Import-,Export-,Test-, andFormat-all build on these two functions.Request
Desired capability
ConvertFrom-PowerShellDataFileparameters-InputObjectValueFromPipeline, default set, position 0)-SkipLimitCheckImport-PowerShellDataFile)Returns
[hashtable]— same shape as the built-inImport-PowerShellDataFile.ConvertTo-PowerShellDataFileparameters-InputObjectValueFromPipeline, position 0)-Depth-Indent-EnumsAsStringsReturns
[string].Acceptance criteria
ConvertFrom-PowerShellDataFileparses PSD1 content using the PowerShell AST (noInvoke-Expression, same safety asImport-PowerShellDataFile)Import-PowerShellDataFilefor the same contentConvertTo-PowerShellDataFileproduces output that round-trips throughConvertFrom-PowerShellDataFilenull,[datetime],[guid],[char],[scriptblock](per the documented subset)[pscustomobject]instances should be converted to hashtable first or rejected with guidance)Technical decisions
Parser approach: Use
[System.Management.Automation.Language.Parser]::ParseInput()and walk the resulting AST. This matches how the built-inImport-PowerShellDataFilevalidates safety. NoInvoke-Expression, noiex, no shelling out.Allowed types: Mirror the documented PSD1 subset. Reject other types at serialization time with a clear error.
Function placement:
src/functions/public/ConvertFrom-PowerShellDataFile.ps1andsrc/functions/public/ConvertTo-PowerShellDataFile.ps1.Aliases:
ConvertFrom-Psd1/ConvertTo-Psd1for shorter common usage.Output types:
[hashtable]forConvertFrom,[string]forConvertTo.Indent default: 4 spaces — matches the PowerShell module manifest convention generated by
New-ModuleManifest.Relationship to existing functions: Replaces the placeholder
Set-PSModuleTestfunction in the repo. Cleanup is part of this issue.Breaking changes: None — there are no real public functions today.
Implementation plan
Core functions
ConvertFrom-PowerShellDataFileinsrc/functions/public/ConvertFrom-PowerShellDataFile.ps1withConvertFrom-Psd1aliasConvertTo-PowerShellDataFileinsrc/functions/public/ConvertTo-PowerShellDataFile.ps1withConvertTo-Psd1aliasTests
tests/ConvertFrom-PowerShellDataFile.Tests.ps1— basic hashtable, nested hashtable, arrays, all allowed scalar types, malformed inputtests/ConvertTo-PowerShellDataFile.Tests.ps1— round-trip viaConvertFrom-PowerShellDataFile, type rejection,-Indent,-Depth,-EnumsAsStringsConvertFrom-PowerShellDataFilematchesImport-PowerShellDataFilefor identical content written to a temp fileCleanup
Set-PSModuleTestand its testexamples/General.ps1and README