I have a generic text, not PSCustom, not CSV, not JSON but has some structure
Field1:ABC Field2: DEF Field1:HKA Field3:YZ Field1:123 Field2:234 Field4:876 Field5:XUZ
Obviously, the text is a multiple records with fields and missing fields, each record is separated with CR-LF.
Is there an efficient way to parse the string and extract only Field1 and Field2 out of the records and put the results in JSON?
I tried put the string into a string variable called $s then
$s | select -ExpandProperty Field1,Field2 But I got this error
Select-Object : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ExpandProperty'. Specified method is not supported.
If I tried
$s | select -ExpandProperty Field1 Then I got the error saying Field1 not being a property.
I guess I kinda understand the error but not sure how to fix it. I think I have to somehow convert the text into a structured table first then extract it. But how do I do that?