Refresh QR code after AAD join detected

The QR code text was built once at script startup. If the device wasn't
AAD-joined yet, it showed "Device not yet Azure AD joined" forever -
even after Phase 1 checks passed. Now regenerates Build-QRCodeText
when Phase1.AzureAdJoined transitions to true.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-04-10 14:38:15 -04:00
parent b69d68f7b5
commit 15f67063bd

View File

@@ -636,6 +636,7 @@ function Invoke-RebootPrompt {
# ============================================================================
try {
$qrText = Build-QRCodeText
$qrRefreshed = [bool]($qrText -notmatch 'not yet Azure AD joined')
Invoke-IntuneSync
$lastSync = Get-Date
$nextRetrigger = $lastSync.AddMinutes($RetriggerMinutes)
@@ -643,6 +644,14 @@ try {
while ($true) {
$snap = Get-Snapshot
# Refresh QR code once AAD join is detected (the initial build
# may have run before enrollment completed, showing "not yet
# Azure AD joined" even after Phase 1 passes).
if (-not $qrRefreshed -and $snap.Phase1.AzureAdJoined) {
$qrText = Build-QRCodeText
$qrRefreshed = $true
}
Clear-Host
Write-Host "=== Monitor running - transcript: $transcriptPath ===" -ForegroundColor DarkGray
foreach ($l in (Format-Snapshot -Snap $snap -LastSync $lastSync -NextRetrigger $nextRetrigger)) {