Write-Progress not working in foreach loop

Hi,

I wrote a PS Script to compare users or groups from two different LDAP repositories. This is working fine, as long as I don’t user Write-Progress in the first loop. If I use it, the loop will end after the first run.
The Write-Progress in the inner foreach is working fine.

Any idea?

This is the part of the Script with the Write-Progress:

$x=0
foreach($r in $Results)
{
    $x++
    
    $Res = $r | select -Expand Properties | select @{n='distinguishedName';e={$_.adspath.split("/")[3]}}, @{n=$i.attribute;e={$_.($i.attribute.ToLower())}}
 
    $searcher_2.Filter = $res.distinguishedName.split(",")[0]
    $dis = $searcher_2.FindAll()
    $dis2 = $dis | select -Expand Properties | select @{n='distinguishedName';e={$_.adspath.split("/")[3]}}    
    if($dis2.distinguishedname -eq $res.distinguishedName) 
    {
            $y=0
            foreach ($i in $PropList)
            {
                $y++
                if($i.Required -eq "required")
                        {
                            $dis | select -Expand Properties | select @{n=$i.attribute;e={$_.($i.attribute.ToLower())}}
                            [string]$TempSoll = $res.($i.attribute)
                            if ($TempSoll) { if ($tempSoll[0] -eq "0") {$tempSoll = "'" + $tempSoll}}
                            [string]$TempIST = $dis.Properties.($i.attribute.ToLower())
                            if ($TempIST) { if ($TempIST[0] -eq "0") {$TempIST = "'" + $TempIST}}
                            if ($TempIST -eq $TempSoll) {$TempVergleich = "WAHR"} else {$TempVergleich = "FALSCH"}
                            Add-Content -Path $outfile -Value ($res.distinguishedName + ";" + $dis2.distinguishedname + ";" + $i.Attribute + ";" + $tempSoll + ";" + $TempIST + ";" + $TempVergleich)
                        }
                Write-Progress -id 2 -Activity "Compare Objects"  -Status "Object $i" -PercentComplete ($y / $proplist.count * 100)
            }
    
    }
    else
    {
        Add-Content -Path $outfile -Value ($res.distinguishedName + ";;;;;" + "NA")
    }
Write-Progress -id 1 -Activity "Compare Objects"  -Status "Object $r" -PercentComplete ($x / $results.count * 100)
}

The variable $PropList is not listed before the second foreach loop (foreach ($i in $PropList)). Write-Progress has no values to work with.