Part of some text file (pfile.ora) looks like this:
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)'
In that file, 1 parameter needs to be updated. I found this function somewhere to read and parse the file:
function Parse-IniFile ($file) {
$ini = @{}
switch -regex -file $file {
"^\s*([^#].+?)\s*=\s*(.*)" {
$name,$value = $matches[1..2]
$ini[$name] = $value.trim()
}
}
$ini
}
The result is stored in variable $aLines:
$aLines = Parse-IniFile ('pfile.ora');
After updating the parameter:
$aLines.'*.db_recovery_file_dest' = "'\\nas4\backup\SRV07\fast_recovery_area\fubar'";
... displaying the contents of $aLines results in:
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...
The elements are all completely unordered! I need them ordered as they were. After:
$sOut = "";
foreach($oLine in $aLines.GetEnumerator() ) {
$sOut += $oLine.name + "=" + $oLine.value +"`r`n";
}
and writing $sOut to file no line is at its original location anymore.
Long story, simple question: how do I get the result back as it was, still being able to easily change one of the parameters?
Any help would be greatly appreciated!