I have a generic text, not PSCustom, not csvCSV, not jsonJSON but has some structure
Field1:ABC Field2: DEF Field1:HKA Field3:YZ Field1:123 Field2:234 Field4:876 Field5:XUZ 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 crlfCR-LF.
Is there an efficient way to parse the string and extract only Field1Field1 and Field2Field2 out of the records and put the results in jsonJSON?
I tried put the string into a string variable called $s$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. 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 Field1Field1 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?
Please help..