title: How to convert a plain text into a structured PowerShell object
body: <p>I have a generic text, not PSCustom, not CSV, not JSON but has some structure</p>
  
  <pre>
  Field1:ABC
  Field2: DEF
  
  Field1:HKA
  Field3:YZ
  
  Field1:123
  Field2:234
  Field4:876
  Field5:XUZ
  </pre>
  
  <p>Obviously, the text is a multiple records with fields and missing fields, each record is separated with CR-LF.</p>
  
  <p>Is there an efficient way to parse the string and extract only <code>Field1</code> and <code>Field2</code> out of the records and put the results in JSON?</p>
  
  <p>I tried put the string into a string variable called <code>$s</code> then</p>
  
  <pre><code>$s | select -ExpandProperty Field1,Field2
  </code></pre>
  
  <p>But I got this error</p>
  
  <blockquote>
    <p>Select-Object : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ExpandProperty'. Specified method is not supported.</p>
  </blockquote>
  
  <p>If I tried </p>
  
  <pre><code>$s | select -ExpandProperty Field1
  </code></pre>
  
  <p>Then I got the error saying <code>Field1</code> not being a property.</p>
  
  <p>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?</p>