$csv = import-csv C:\users\ewpmni\csv.csv -Delimiter ';'

$count = 0
$csv2 = foreach($entry in $csv) {
    $count++
    Write-progress -Activity "Finding nonacked" -Status "$count / $($csv.Count)"

    $matches = foreach($c in $csv) {
        if($c.filename -eq $entry.filename) { 
            $c
        }
    }

    $isack = $false

    foreach($m in $matches) {
        if($m.dateofack -ne 'never positif ack ') {
            $isack = $true
            break
        }
    }

    if(-not $isack) {
        $entry
    }
}



$count = 0
$csv3 = foreach($c in $csv2) {
    $count++
    Write-progress -activity "csv" -status "$count / $($csv2.Count)"
    $path = "T:\m.nielsen\missingtransactions\$($c.server)\OutgoingNotProcessed\$($c.Date)\REJK-P-MDL003V\dcp_ud\$($c.Filename)"
    $item = Get-Item -Path $path

    [pscustomobject]@{
        Filename = $c.Filename
        DateOfAck = $c.DateOfAck
        Server = $c.Server
        Date = $c.Date
        DateFormatted = [datetime]::ParseExact($c.date, 'yyyyMMdd', [cultureinfo]::InvariantCulture)
        DateModified = $item.LastWriteTime
    }
}


$count = 0
$sql = foreach($c in $csv3) {
    $count++ 
    Write-progress -activity "csv" -status "$count / $($csv2.Count)"

    Write-Output "(N'$($c.Filename)', '$($c.DateModified.ToString('yyyy-MM-dd HH:mm:ss'))',0, NULL)"

}


$csv3 | select Filename, DateModified | Export-Csv -NoTypeInformation -Delimiter ';' T:\m.nielsen\MissingTransactions\csv2.csv -NoClobber