Posts

Showing posts from May, 2022

Converting nested hashtables(or yaml) to nested psobject with PowerShell

Image
I'm dabbling with WinGet at work, and I wanted to parse the installer information about VLC Media Player provided by WinGet .  PowerShell does not natively support Yaml, so I like to use the powershell-yaml module. I thought a simple convert should be enough, but no. This just resulted in a hashtable, I wanted a psobject. So how about casting ut to a psobject? Better, at first I thought I was done. But hold on, the properties of Installers are still hashtables. Googling and thinking led me to almost use a recursive function that dealt with this, but then I remembered playing around with conversions between yaml and json. Side note, the UI config of Home Assistant may be edited as yaml, but is stored as json on disk. So I knew they are just different flavors of the same thing, really.  Anyways, this is how to convert yaml to nested psobects: Get-Content <file.yaml> | ConvertFrom-Yaml | ConvertTo-Json | ConvertFrom-Json (I added -Depth 5 just because the default value 2 is not