Skip to content

PowerShell data/hashtable format conversion cmdlets #11300

@rjmholt

Description

@rjmholt

Summary of the new feature/enhancement

Today, it's hard to manipulate PowerShell PSD1/hashtable syntax. Import-PowerShellDataFile provides some options, but it only goes one way, requires a file, and doesn't work with all files ending in psd1 (module manifests allowing "Restricted Language Mode", so having things that ordinary data syntax does not allow).

To make the PowerShell data syntax a first class citizen within PowerShell, I think we would need:

  • ConvertTo- and ConvertFrom- cmdlets
  • Efficient and consistent [de]serialisation for hashtables, pscustomobjects and arbitrary objects in the usual way
  • Support for the extended restricted language mode syntaxes enabled by switches
  • An API available to do this without a cmdlet. One place this would help is with the ModuleSpecification ToString() implementation, which today hand writes psd1 hashtable format.

Proposed technical implementation details (optional)

I have a small prototype here, but I propose the following:

  • ConvertTo-Psd and ConvertFrom-Psd being the cmdlets
  • Following the standard JSON cmdlet conventions, with Depth and Compress or similar parameters
  • Having a switch for enabling restricted language mode parsing (which will require the full PowerShell parser), perhaps -WithFullParsing or similar Now that I understand this better, I don't think it fits well with this proposal; restricted language mode parsing is specific to module manifests and doesn't reflect broader usage of PSD format

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions