title: Powershell read/update/write parameter file
body: <p>Part of some text file (pfile.ora) looks like this:</p>
  
  <pre><code>fubar.__db_cache_size=1040187392
  fubar.__pga_aggregate_target=1291845632
  *.audit_file_dest='C:\app\oracle\admin\fubar\adump'
  *.db_recovery_file_dest='\\nas3\backup\SRV07\fast_recovery_area\fubar'
  *.db_recovery_file_dest_size=42949672960
  *.dispatchers='(PROTOCOL=TCP) (SERVICE=fubarXDB)'
  </code></pre>
  
  <p>In that file, 1 parameter needs to be updated. I found this function somewhere to read and parse the file:</p>
  
  <pre><code>function Parse-IniFile ($file) {
     $ini = @{}
     switch -regex -file $file {
        "^\s*([^#].+?)\s*=\s*(.*)" {
           $name,$value = $matches[1..2]
           $ini[$name] = $value.trim()
        }
     }
     $ini
  }
  </code></pre>
  
  <p>The result is stored in variable $aLines:</p>
  
  <pre><code>$aLines = Parse-IniFile ('pfile.ora');
  </code></pre>
  
  <p>After updating the parameter:</p>
  
  <pre><code>$aLines.'*.db_recovery_file_dest' = "'\\nas4\backup\SRV07\fast_recovery_area\fubar'";
  </code></pre>
  
  <p>... displaying the contents of $aLines results in:</p>
  
  <pre><code>Name                              Value
  ----                              -----
  *.db_recovery_file_dest          '\\nas3\backup\SRV07\fast_recovery_area\fubar'
  fubar.__db_cache_size            1040187392
  fubar.__pga_aggregate_target     1291845632
  *.audit_file_dest                'C:\app\oracle\admin\fubar\adump'
  etc...
  </code></pre>
  
  <p>The elements are all completely unordered! I need them ordered as they were. After:</p>
  
  <pre><code>$sOut = "";
  foreach($oLine in $aLines.GetEnumerator() ) {
     $sOut += $oLine.name + "=" + $oLine.value +"`r`n";
  }
  </code></pre>
  
  <p>and writing $sOut to file no line is at its original location anymore.</p>
  
  <p>Long story, simple question: how do I get the result back as it was, still being able to easily change one of the parameters?</p>
  
  <p>Any help would be greatly appreciated!</p>