I wrote a simple script, that searches through the files for a certain string and writes those matched lines into a new file. Why doesn't it overwrite the file when I execute the script again? In documentation says that Out-File overwrites existing file
by default. In my case it only adds same lines to the output file. What am I missing?
This is the script:
$FilePath = 'E:\test'
$files = Get-ChildItem $FilePath\*.txt
$rezultat = @()
foreach ($file in $files) {
$rezultat+= Get-Content $file | Select-String $string -Context 0 -SimpleMatch
}
$rezultat | Out-File E:\test\rezultat.txt