Skip to content

PowerShell should contain Export-PowershellDatafile cmdlet that safely and correctly persists property bags #2875

Open

Description

As a developer working on tooling, I find the ability to READ PSD1 files via Import-PowershellDataFile cmdlet incredibly handy. Importing a powershell data file (.psd1) is nice because the format is quite user-friendly and readable format. It's just not easily writeable. Which seems a big oversight. I have learned that the most common term for the things you would write is a "property bag".

A property bag is really Arrays in key,value form, which contain other Arrays in key,value form, and a way to write that to disk easily in one cmdlet seems to be missing. I find it useful to build up some configuration or state in an Array variable, sometimes containing Arrays within arrays, something like this:

     @{
     Version  = '1.0.0'
     Name     = 'thing'
     Revision = 'c3a89cd20e19bb82f41e95e0806edc5b6cfd224e'
     Date     = '2016-12-09'
     Build    = '1234'
     Contents = @{
          "index.html" = "23dd7b993f40bb3ae8848fe104b3b767"
     }
     }

I actually asked this as a question on stackoverflow here.

Because I also use python a lot, I looked around for someone who wrote a repr()-like function. Python's fully dynamic nature is similar in many ways to PowerShell's, so it is even more surprising to me that the there are basic holes of "orthogonality", that is missing features, like this.

I could try to write something myself, but it seems to me that this should be built into PowerShell. Initially I would want it to be a complete opposite or "counterpart" to Import-PowershellDatafile.

Activity

  1. changed the title [-]PowerShell should contain Export-PowershellDatafile cmdlet that securely persists arbitrary variables.[/-] [+]PowerShell should contain Export-PowershellDatafile cmdlet that safely and correctly persists arbitrary variable content[/+] on Dec 12, 2016
  2. wpostma commented on Dec 12, 2016

    @wpostma
    Author

    Existing functionality is that you can load XML into Powershell variables, and save back to XML with export-clixml but it seems that PSD1 format would be more native, and more readable than doing this with XML.

  3. wpostma commented on Dec 12, 2016

    @wpostma
    Author

    Also found that some people have implemented this themselves. The value of building something like this in becomes more clear when you see that there are multiple almost-good-enough implementations out there, and that none of them works quite exactly perfectly, is a good argument for building this INTO powershell, so if I run into more kludges of this sort, I'll keep adding them as comments.

    Export-PSData sample works with some trivial @{ "a"="b"} cases, but not with others.
    https://www.gitlab.com/warren.postma/hai/snippets/33366

  4. changed the title [-]PowerShell should contain Export-PowershellDatafile cmdlet that safely and correctly persists arbitrary variable content[/-] [+]PowerShell should contain Export-PowershellDatafile cmdlet that safely and correctly persists property bags[/+] on Dec 13, 2016
  5. added
    WG-Engine
    Review - Committee
    on Dec 14, 2016
  6. added
    WG-Cmdlets
    Issue-Enhancement
    Committee-Reviewed
    Up-for-Grabs
    and removed
    WG-Engine
    Review - Committee
    on Jan 12, 2017
  7. SteveL-MSFT commented on Jan 12, 2017

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee discussed this and agree this would be useful for example to programmatically modify a module manifest

  8. Outek commented on Nov 30, 2017

    @Outek

    Any news on this issue?

  9. SteveL-MSFT commented on Nov 30, 2017

    @SteveL-MSFT
    Member

    Daniel Siegenthaler (@Outek) there are currently no plans for the PowerShell Team to implement this hence being labeled as Up-for-Grabs

  10. 13 remaining items

  11. SeidChr commented on Nov 26, 2023

    @SeidChr

    And yes, Christian Seidlitz (@SeidChr) There are a lot of reasons why every language/framework has to have a package gallery. It's better to install a few modules for the functionality you need, than to ship every scrap of functionality in the core shell installer. Most people need only a few parts of the functionality, and we certainly can't afford to download all of it (and then keep downloading the upgrades). Have you seen how big the Az modules are? Or VMWare.PowerCli? On top of all of that, we need to decouple the development, to free thousands of people to work on all that functionality at their own pace.

    We are not talking about a cloud integration for some random provider. We are talking about serializing data into the native PowerShell data format.
    Even json is integrated, but .psd1 is not? How does this make sense?

    Also please note: I'm not criticizing your module. Just some of the decisions made on what should be in PowerShell and what not. I feel this just hinders it's utility, and thus it's success. There are many 'issues' (imo) like these which are around for many years. People just got so used to working around, that there is no hope for these tickets ever being picked up again.

  12. rhubarb-geek-nz commented on Nov 26, 2023

    @rhubarb-geek-nz

    Just some of the decisions made …

    I don't really know why the psd1 format was chosen for modules in the first place. A csproj is XML, a nuspec definition is XML, the PSGetModuleInfo file PowerShell writes in the installed directory is in XML …

  13. removed
    Resolution-No Activity
    on Sep 1, 2026
  14. kilasuit commented on Sep 1, 2026

    @kilasuit
    Collaborator

    I don't really know why the psd1 format was chosen for modules in the first place.

    PSD1 format would be more native, and more readable than doing this with XML. I mean we've moved away from XML in many places to JSON, YAML, TOML etc though PSD1 is a better format that they where.

    Which was why XML wasn't picked in the first place. It was the right decision then & now.

    I don't see why other than engineering effort/support on why there wasn't ever an Export-PowerShellDataFile cmdlet added, or yet why we haven't added/recommended a community module for this/similar needs.

    As such I am opening this for the Cmdlets WG to discuss this issue, but specifically around desire & what the criteria would need to be for future inclusion for any potential inclusion of community developed modules into future releases. I know that there has been previously talks on there being releases of things like a community developed DevOps modules to the Gallery to bundle community offerings that can be more easily added either as part of the project releases or recommended via tooling like the CommandNotFound tooling that has been implemented since the project was initially open sourced.

  15. rhubarb-geek-nz commented on Sep 1, 2026

    @rhubarb-geek-nz

    I think bundling things that are already in PSGallery defeats the purpose of PSGallery. The direction should be unbundling, eg like the suggestion to remove Show-Markdown and move that to gallery.

    I find CommandNotFound has little use because I never run a tool like this manually, it is always part of a scripted pipeline, eg

    $moduleSettings = @{
    	Path = "$OutDir$ModuleId.psd1"
    	...
    }
    
    New-ModuleManifest @moduleSettings
    
    Import-PowerShellDataFile -LiteralPath "$OutDir$ModuleId.psd1" | Export-PowerShellDataFile | Set-Content -LiteralPath "$PublishDir$ModuleId.psd1" -Encoding utf8BOM
    

    Another solution would be to have an option to remove all the comments generated by New-ModuleManifest, then it would not be needed. One should not be hand editing module manifests, they should be generated to comply with the module import requirements..

  16. Chirishman commented on Sep 1, 2026

    @Chirishman

    I think bundling things that are already in PSGallery defeats the purpose of PSGallery. The direction should be unbundling, eg like the suggestion to remove Show-Markdown and move that to gallery.

    I disagree, that module is in the gallery because this has been ignored for 13+ years.

    PSD1 is intrinsic to PowerShell like JSON is to Javascript (as has been said before)

    Fundamentally psd1 files (a format used by no language other than PowerShell and which isn't going to stop being used by PowerShell) can be imported by a bundled PowerShell command and exporting them in the same serialized format should likewise be supported. Markdown you could make such an argument if you wanted to because Markdown is external to PowerShell itself and not intrinsic to it.

    Moreover think about it this way: if you abstracted the entirety of the reciprocal capability, the ability to import this format to a separate module along with export capability you would be abstracting out a capability required to actually import a module in the first place. If the ability to work with a format is fundamental to the ability to import modules at all then all commands pertaining to it should be considered core functionality.

    Potential for user confusion, incomplete and inconsistent functionality

    There should be one canonical answer for exporting in this format which is available as part of the core functionality just like the corresponding import command. It is not beneficial to have, as can be found by reading this thread back, multiple different attempts where people write a version that pretty much does just enough of the job to solve the author's own use case.

    Things would be worse actually if there were a half dozen different community written export-clixml functions that did better and worse jobs of serializing things and handling edge cases.

  17. rhubarb-geek-nz commented on Sep 1, 2026

    @rhubarb-geek-nz

    Moreover think about it this way: if you abstracted the entirety of the reciprocal capability, the ability to import this format to a separate module along with export capability you would be abstracting out a capability required to actually import a module in the first place. If the ability to work with a format is fundamental to the ability to import modules at all then all commands pertaining to it should be considered core functionality.

    There is no problem with having asymmetric capabilities, Windows as shipped can install an MSI but can't build an MSI (you need Wix), the Java runtime can't compile a java program, you need the SDK.

    You might say that the ability to install a powershell module is fundamental to PowerShell, but that has been moved to PSGallery, see PowerShellGet and the PowerShell Gallery

  18. kilasuit commented on Sep 2, 2026

    @kilasuit
    Collaborator

    I think bundling things that are already in PSGallery defeats the purpose of PSGallery.

    The direction should be unbundling, like the suggestion to remove Show-Markdown and move that to gallery.

    Generally, I don't disagree with unbundling, especially as I raised an early request for this in #1979, however realism says that it's hard to unbundle the things that are included in core modules, and where we identify gaps in this project that are well built and potentially suitable for inclusion as part of a PowerShell Release, how do we look at doing this in the future.

    There is no problem with having asymmetric capabilities

    Actually there is for things like this. It breaks a simple user expectation, in for all imports there should where reasonable for there to be a export process too.

    Especially as this issue is about more than just PowerShell Module Manifests and rightly so as this format can be used for other things, like holding the data needed for PowerShell DSC 1.1 Configurations as used by the Lability Module though this isn't the only example I can give, just unfortunately the only public one that I can give.
    Except that it might also lead to pds1 files be a format that tooling like DSC supports in future.

    Another solution would be to have an option to remove all the comments generated by New-ModuleManifest, then it would not be needed. One should not be hand editing module manifests, they should be generated to comply with the module import requirements..

    I'd be happy with that being flouted as an improvement to that cmdlet and needs an issue so that work can be tracked.

    But still doesn't stop the need for to be a revisited discussion about what the bar for any future acceptance of a community module like Joel Bennett (@Jaykul)'s Metadata Module or Jordan Borean (@jborean93) Yaml module might look like (if it were to happen at all that is, especially with the move to inbox pwsh 7 in Windows)

    (Also aware that we may want to highlight in docs/blogs etc where there are gaps like this one)

  19. moved this from Queue to In-Progress-Issues in Cmdlets Working Groupon Sep 2, 2026
  20. moved this from In-Progress-Issues to Reviewed in Cmdlets Working Groupon Sep 2, 2026
  21. wpostma commented on Sep 9, 2026

    @wpostma
    Author

    Original author of this bug here.

    This was logged in 2016. It's 2026. I've long since given up on the utility of Powershell Classic or PWSH 7 for system management work, or my other main purpose, which is continuous integration build scripting. That is where a simple round trip data format, native to powershell comes from. Build.ps1 and buildconfig-win32.cfg configuration files. It bothered me to see someone bothered to create a readable format that wasn't natively writeable. Dead simple. Surely an omission. Decade later, and no, it's not an omission, it's by design, clearly. Imagine an SQL variant with SELECT but no INSERT or UPDATE. The mind boggles.

    This recent reopen-then-comment-discussion is amusing because it shows how Powershell goes; Around and around in circles.

    Why have builtins when you have PSGallery? Why have powershell at all then, when we have the internet and we can download literally anything, including Python which is like Powershell but better. More readable. Better tooling. More orthogonal standard library. Easier to use packaging system. Better version management.

    Powershell 7's autocomplete is nice, and everything, but it's all ten years too late if you ask me. Why use an MS-platform-centric shell scripting language at all when you should just be using Python.

    PowerShell, as a shell, is fine, I certainly don't use cmd.exe anymore on Windows. PowerShell as a language, is an abomination.

    But it's finally got me thinking. Why do I use powershell when its disappointed me for decades? Muscle memory. IDK. I love short memorable names like Get-HammerFactoryFactorialFactorFaction.

    An orthogonal and fully-reasonable set of Builtins are an affordance, a set of basics you don't have to maintain or outsource from a module, a happy path for happy users. But that ship has sailed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedIssue-EnhancementUp-for-GrabsWG-Cmdlets

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions