PowerShell: my ConfigFile that is succesfully written has gone away as soon as the script ends?
my script stores key values in a hash, so that the line with those keyes are not treated again. Each time a new key is stored the has is saved:
function readConf($File) { $H = @{} if (test-path -path $File) { Get-Content $File | ForEach-Object { $x = $_ -replace "-", "" $x = $x -replace "Name", "" $x = $x -replace "Value", "" $x = $x.Trim() $L = $x -split "\s{3,}" #echo(" ok: "+$L+" $H[ $L[0] ] = $L[1] $H.Neu = Get-Date -uformat "%Y.%m.%d %H:%M:%S" } } $H } hConf = readConf($confFile) # no problem so far" ... while ($true) { ... if ( $hConf[$key] ) { continue } $hConf[$key] = $val $hConf > $confFile ... } # end of endless while
As long as this script is running I can see and open this configFile, everything is there, what should be there. But as s开发者_StackOverflow社区oon as I stop the script (by Ctrl-c or in the ISE click on the red button) my configfile is gone, it just disapeared??
Other files that were written the same time line by line still exist?Of course I check that I don't have e file-delete, but even if I would store an empty hash by what ever reason, I think I see an empty file - but the Config-File is gone?
Does anybody know a reson for that? Thanks in advance,
goolyI'm not quite following what you're trying to do, but:
$hConf > $confFile
doesn't look right. You probably want:
$hConf >> $confFile
or
$hConf | out-file -append $conffile
-Oisin
精彩评论