$p = '19mNqNXIoZ4c3EriFNfzfkgpGNOvLjpOqqZnTFXKnzjxWJ5zURjgJQQJ99CBACAAAAAamI5kAAASAZDOAMPp'
$t = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(':' + $p))
$h = @{ Authorization = 'Basic ' + $t }
$base = 'https://dev.azure.com/CN-Squad/Invista%20FIDC%20-%20Nexus/_apis'

foreach ($buildId in @(6181, 6182, 6185, 6186)) {
  $b = Invoke-RestMethod -Uri "$base/build/builds/$buildId`?api-version=7.0" -Headers $h
  $tl = Invoke-RestMethod -Uri "$base/build/builds/$buildId/timeline?api-version=7.0" -Headers $h

  $running = $tl.records | Where-Object { $_.state -eq 'inProgress' } | Select-Object -First 1
  $last    = $tl.records | Where-Object { $_.state -eq 'completed' } | Sort-Object finishTime | Select-Object -Last 1

  $current = if ($running) { $running.name } elseif ($last) { $last.name } else { '?' }
  Write-Host "$($b.definition.name) (build $buildId): $($b.status) — etapa atual: $current"
}
