title: Powershell - ext File parse
body: <p>I know powershell (enough to get my by); however, i have ran into an issue in which i cant even find the answer on google..</p>
  
  <p>I have this test.audit file (for example) that contains</p>
  
  <pre><code>#####################################
  # test here blah blah
  # text
  # 1.23 
  # sample
  #####################################
  
      &lt;check_type&gt;
      # 1.2
      &lt;custom_item&gt;     
          system                 : "Linux"
          type                     : "CHECK"
          description           : "8.1.1.1 text blah blah"
      &lt;/custom_item&gt;      
      &lt;custom_item&gt;       
          system                 : "Linux"
          type                     : "CHECK"
          description           : "8.1.1.2 other text blah blah"
      solution              : "Set the max_log_file data and equal &lt;mb&gt;"
      &lt;/custom_item&gt;  
      # 1.4    
      &lt;custom_item&gt;       
          system                 : "Linux"
          type                     : "CHECK"
          description           : "8.1.1.1 more text blah blah"
      &lt;/custom_item&gt;      
      &lt;custom_item&gt;       
          system                 : "Linux"
          type                     : "CHECK"
          description           : "8.1.1.3 text blah blah"
      &lt;/custom_item&gt;       
      &lt;/check_type&gt;
  </code></pre>
  
  <p>Using that test.audit file.. I am trying to delete the entire "custom_item" string that contains a description of "8.1.1.1".</p>
  
  <p>So the new file would look like</p>
  
  <pre><code>#####################################
  # test here blah blah
  # text
  # 1.23 
  # sample
  #####################################
  
      &lt;check_type&gt;
      # 1.2     
      &lt;custom_item&gt;       
          system                 : "Linux"
          type                     : "CHECK"
          description           : "8.1.1.2 other text blah blah"
      solution              : "Set the max_log_file data and equal &lt;mb&gt;"
      &lt;/custom_item&gt;  
      # 1.4         
      &lt;custom_item&gt;       
          system                 : "Linux"
          type                     : "CHECK"
          description           : "8.1.1.3 text blah blah"
      &lt;/custom_item&gt;       
      &lt;/check_type&gt;
  </code></pre>
  
  <p>I had someone help me however they tried to use the "XML" technique through powershell..</p>
  
  <p>however, this will not work for several reason.. 
  it contains a "#"
  and it also has "" inside it which throws an error. </p>
  
  <p>There was also one more solution </p>
  
  <pre><code>#$text = gc c:\temp\test.audit | Out-String
  
  $text = @'
  &lt;check_type&gt;
  &lt;custom_item&gt;     
      system                 : "Linux"
      type                     : "CHECK"
      description           : "8.1.1.1 text blah blah"
  &lt;/custom_item&gt;      
  &lt;custom_item&gt;       
      system                 : "Linux"
      type                     : "CHECK"
      description           : "8.1.1.2 other text blah blah"
  &lt;/custom_item&gt;      
  &lt;custom_item&gt;       
      system                 : "Linux"
      type                     : "CHECK"
      description           : "8.1.1.1 more text blah blah"
  &lt;/custom_item&gt;      
  &lt;custom_item&gt;       
      system                 : "Linux"
      type                     : "CHECK"
      description           : "8.1.1.3 text blah blah"
  &lt;/custom_item&gt;       
  &lt;/check_type&gt;
  '@
  
  [string]$text = $text -replace '&lt;custom_item&gt;', '=' -split '=' | ? {$_ -notmatch '8.1.1.1'}
  
  $text = $text.Split("`n") | % {if ($_ -match '^\s+$') {'    &lt;custom_item&gt;'} else {$_}}
  
  $text #| out-file c:\temp\test.audit
  </code></pre>
  
  <p>however this outputs the document to be very messy.. not line for line like it was</p>
  
  <p>If someone could assist that would be appreciated.</p>
  
  <p>thanks</p>