File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -454,6 +454,34 @@ try {
454454 Write-Host " `n Script execution stopped.`n " - ForegroundColor Red
455455 exit 1
456456 }
457+
458+ # Check for invalid domain error
459+ if ($_.Exception.Message -match ' domain.*invalid|verified domain|InvalidValue.*userPrincipalName' ) {
460+ $errorDetails = if ($_.ErrorDetails.Message ) {
461+ ($_.ErrorDetails.Message | ConvertFrom-Json ).error.message
462+ }
463+ else {
464+ $_.Exception.Message
465+ }
466+ Write-Host " FAILED: Invalid domain in UserPrincipalName" - ForegroundColor Red
467+ Write-Verbose " Domain validation error: $errorDetails "
468+ Write-Host " Error: $errorDetails " - ForegroundColor Yellow
469+
470+ # Continue to next user instead of stopping
471+ $failCount ++
472+ $results.Add ([PSCustomObject ]@ {
473+ UserPrincipalName = $userPrincipalName
474+ DisplayName = $displayName
475+ Status = ' Failed'
476+ Password = $null
477+ ObjectId = $null
478+ Error = $errorDetails
479+ })
480+ Write-Verbose " Error result stored in collection"
481+ Write-Host " "
482+ continue
483+ }
484+
457485 # Re-throw other errors to be caught by outer catch block
458486 throw
459487 }
You can’t perform that action at this time.
0 commit comments