You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PowerShell has Import-PowerShellDataFile for reading .psd1 files, however there is no built-in way to serialize PowerShell objects into .psd1 literal syntax.
A lot of people end up writing their own implementations for this. I have my own implementation here:
It would be useful to have a standard ConvertTo-Psd1Literal cmdlet in PowerShell that can convert hashtables, arrays, strings, and other supported values into valid .psd1 syntax.
For example:
$data|ConvertTo-Psd1Literal
This would give users a standard way to generate .psd1 files instead of having to maintain their own implementations.
The implementation could follow the same general approach as existing community implementations and support the types that can be represented as PowerShell data file literals.
The output should be valid .psd1 syntax and ideally round trip correctly through Import-PowerShellDataFile.
The exact supported types and formatting can be decided during implementation.
A PowerShell module with a collection of functions that should have been in PowerShell to start with.
It is just a random bag of ad-hoc scripts that anyone could have written and have no coherence other than some developer might want a couple of them. Apart from the Export-PowerShellDataFile, it has scripts for Git (which is not provided by Windows), for removing items provided by Windows PowerShell (which is a great advert for why more things should not actually be included), and a file content displayer because .. reasons.
I think the test of time has shown there isn't a real need, or if there is PSGallery is quenching that thirst. It is not a common tool, it is a poor proprietary format, JSON or XML would serve general purpose needs far better. The only reason I wrote mine was because of the unwanted commentary/noise generated by New-ModuleManifest.
The output should be valid .psd1 syntax and ideally round trip correctly through Import-PowerShellDataFile.
I would suggest that is the entire purpose rather than a nice to have.
The exact supported types and formatting can be decided during implementation.
I would expect that has already been defined in Data Files
The data in the file must be contained in a hashtable. This format only supports constant values. You can't use code or PowerShell expressions.
Rather than writing anything new, and if it is deemed desirable then I propose my own C# solution previously mentioned.
Activity
rhubarb-geek-nz commentedon Aug 26, 2026
Lets go back to 2016... #2875
said Voldemort while waiting to save his hash table.
Now if you were looking for the reverse of Import-PowerShellDataFile then I expect the natural thing would be to look for Export-PowerShellDataFile rather than
ConvertTo-Psd1Literal.That shows up two. The first is my own rhubarb-geek-nz.PowerShellDataFile. The second is Utilities. Now for the second one, despite the grandiose claim
It is just a random bag of ad-hoc scripts that anyone could have written and have no coherence other than some developer might want a couple of them. Apart from the Export-PowerShellDataFile, it has scripts for Git (which is not provided by Windows), for removing items provided by Windows PowerShell (which is a great advert for why more things should not actually be included), and a file content displayer because .. reasons.
I think the test of time has shown there isn't a real need, or if there is PSGallery is quenching that thirst. It is not a common tool, it is a poor proprietary format, JSON or XML would serve general purpose needs far better. The only reason I wrote mine was because of the unwanted commentary/noise generated by New-ModuleManifest.
I would suggest that is the entire purpose rather than a nice to have.
I would expect that has already been defined in Data Files
Rather than writing anything new, and if it is deemed desirable then I propose my own C# solution previously mentioned.
kilasuit commentedon Sep 1, 2026
I do see value in this however the question was asked previously as mentioned.
I'm going to close this as a duplicate of #2875 & reopen that issue
kilasuit commentedon Sep 9, 2026
As mentioned this was previously asked for in #2875 & in #2783
And would be
Export-PowerShellDataFileinstead ofConvertTo-Psd1Literal