I’m trying to avoid the apparent mess that is the .NET Core querystring parsing classes for now, yes.
For a given string: $data = 'id=1&name=neil&language=powershell'
I’d like to get a hashtable that looks like this:
@{
id = 1
name = 'neil'
language = 'powershell'
}
I’ve tried this:
$data -split '&' | ConvertFrom-StringData
But I actually get an array of hashtables because ConvertFrom-StringData
wants a single newline-separated string. So I tried this:
$data -replace '&','n' | ConvertFrom-StringData
Which is yucky, but also doesn’t work.
Before I end up writing a for
loop, is there a more PowerShell-idiomatic way to do this?