Converts a PowerShell Hashtable object to a PSON-formatted string.
- Download the source code.
- Dot-source
ConvertTo-PSON.ps1in your script. - Call
ConvertTo-PSON, providing aHashtableobject as the only parameter, and assign the resulting value to aStringvariable.
This function currently only understands the following general types of data:
- strings
- integers
- decimals
- date/time
- booleans
$nullHashtables
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.
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.
https://stackoverflow.com/q/15139552
MIT (please refer to the file named LICENSE).