workflow MissingTransactions {
    #$servers = Get-Item "T:\m.nielsen\missingtransactions\*" | Where-Object -FilterScript { $_.Attributes -contains 'directory' }

    $servers = @(
        @{ Name = 'REJK-P-SPS001'; FullName = '\\REJK-P-SPS001\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS002'; FullName = '\\REJK-P-SPS002\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS003'; FullName = '\\REJK-P-SPS003\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS004'; FullName = '\\REJK-P-SPS004\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS005'; FullName = '\\REJK-P-SPS005\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS006'; FullName = '\\REJK-P-SPS006\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS007'; FullName = '\\REJK-P-SPS007\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS008'; FullName = '\\REJK-P-SPS008\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS009'; FullName = '\\REJK-P-SPS009\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-SPS010'; FullName = '\\REJK-P-SPS010\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-DPS001'; FullName = '\\REJK-P-DPS001\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-DPS002'; FullName = '\\REJK-P-DPS002\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-DPS003'; FullName = '\\REJK-P-DPS003\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-DPS004'; FullName = '\\REJK-P-DPS004\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-DPS005'; FullName = '\\REJK-P-DPS005\d-drive\ifsbodata\fsv' }
        @{ Name = 'REJK-P-DPS006'; FullName = '\\REJK-P-DPS006\d-drive\ifsbodata\fsv' }
    )

    
    $dates = foreach ($s in $servers) {
        Get-Item -Path "$($s.FullName)\outgoing_notprocessed_files\*"
    }

    foreach -parallel -throttlelimit 4 ($d in $dates) {
            
        InlineScript { 
            $date = $using:d
			$server = @{
				FullName = $date.FullName.Substring(0, '\\rejk-p-xxxyyy\d-drive\ifsbodata\fsv'.length)
				Name = $date.FullName.Substring(2, 'rejk-p-xxxyyy'.length)
			}


            try {

                $files = Get-ChildItem -Recurse "$($date.FullName)\rejk-p-mdl003v\dcp_ud" -File

                Write-Verbose "$($server.Name) - $($date.Name) - Csv Import"
                $csv = Import-Csv "$($server.FullName)\outgoing_histo\$($date.Name)\fsv_histooutgoing.txt" -Header ('box name ; file name ; date of arrival ; number of retries ; date of last send info ; date of ack ; row of sending ; current date' -split ' ; ') -Delimiter ';'
                
                $dateFormatted = [datetime]::ParseExact($date.Name,'yyyyMMdd', [cultureinfo]::InvariantCulture)

                $filecount = 0
                foreach ($file in $files) {
                    $filecount++

                    try { 
                        Write-Verbose "$($server.Name) - $($date.Name) - $($file.Name) - $filecount / $($files.Count)"
                        
                        $filename = $file.Name

                        $result = foreach($entry in $csv) {
                            if($entry.'file name' -match $filename) {
                                $entry
                            }
                        }
                            
                        foreach($entry in $result) {
                            if($entry.'date of ack' -ne $null) { 
                                [pscustomobject]@{
                                    Filename = $filename
                                    DateOfAck = $($entry.'date of ack')
                                    Server = $server.name
                                    Date = $date.Name
                                }
                            }
                        }
                    }
                    catch {
                        Write-Warning "File $($file.Name) failed: $_"
                    }
                }
            }
            catch {
                Write-Warning "Date $($date.Name) failed: $_"
            }
        }
    }
}

$result = MissingTransactions -Verbose