/ConvertTo-PSON

Converts a PS Hashtable object to a PSON-formatted string.

Primary LanguagePowerShellMIT LicenseMIT

ConvertTo-PSON

Converts a PowerShell Hashtable object to a PSON-formatted string.

Usage

  1. Download the source code.
  2. Dot-source ConvertTo-PSON.ps1 in your script.
  3. Call ConvertTo-PSON, providing a Hashtable object as the only parameter, and assign the resulting value to a String variable.

Limitations

This function currently only understands the following general types of data:

  • strings
  • integers
  • decimals
  • date/time
  • booleans
  • $null
  • Hashtables

It does not yet understand arrays, nor other specific object types (such as PSCustomObject, or Credential, etc).

I've only confirmed that this code works with PowerShell 5 running on .NET Core 2. Additional versions will be tested as soon as I bring this project into a cloud-based CI system.

Why?

I needed this for some TDD that I was doing in PowerShell. If you haven't already, check out Pester!

And if you aren't testing, then get onboard already! Just remember that it's not magic.

Inspiration

https://stackoverflow.com/q/15139552

License

MIT (please refer to the file named LICENSE).