I wrote a powershell script to compare words from a text-file with a csv-column. If the word in the column matches, the line is deleted.
$reader = [System.IO.File]::OpenText($fc_file.Text)
try {
for() {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
if ($line -eq "") { break }
# process the line
$fc_suchfeld = $fc_ComboBox.Text
$tempstorage = $scriptPath + "\temp\temp.csv"
Import-Csv $tempfile -Delimiter $delimeter -Encoding $char | where {$_.$fc_suchfeld -notmatch [regex]::Escape($line)} | Export-Csv $tempstorage -Delimiter $delimeter -Encoding $char -notypeinfo
Remove-Item $tempfile
Rename-Item $tempstorage $tempfile_ext
}
}
finally {
$reader.Close()
}
My code works great, but it is very slow, due to saving and copying the csv file after every line. Is there a way to improve it?