I have a script that should look in a CSV file and modify it. My file looks like this:
"mydata","module1","module2","module3","module4","module5" "kk-ll","module1","","module3","","" "kk-pp","module1","","module3","",""
In case the data in column mydata exists: modify value in column $Module.
In case it does not exist: add a new line to the file.  
The code I wrote for the fist part is OK, for the second part (updating the file) it's not working.
$ExistingCSV = Import-Csv MyCsv.csv
if ($ExistingCSV.mydata -eq "$LOT-$WID") {
    $ExistingCSV | ForEach-Object {
        if ($_.mydata -eq "$LOT-$WID") {
            $_.$Module = $Module
        }
    }
    $ExistingCSV | Export-Csv $ProgressLogPath\$LOT.csv -NoTypeInformation
} else {
    $ExistingCSV.mydata = "$LOT-$WID"
    $ExistingCSV.$Module = $Module
    Add-Content $ExistingCSV -Value $_.Lot_WaferID $_.$Module $_.ScriptLogPath
    $ExistingCSV | Export-Csv $ProgressLogPath\$LOT.csv -NoTypeInformation
}
