# Connect to Azure AD and check account details Install-Module -Name AzureAD Import-Module AzureAD Connect-AzureAD $azureUser = Get-AzureADUser -Filter "UserPrincipalName eq '%UserName%'" if ($null -eq $azureUser) { Write-Host -ForegroundColor Red 'Error: Username not found in Azure AD' pause exit } else { Write-Host -ForegroundColor Cyan ('Azure AD User: ' + $azureUser.DisplayName) Write-Host -ForegroundColor Cyan ('Account Enabled: ' + $azureUser.AccountEnabled) if (-not $azureUser.AccountEnabled) { Write-Host -ForegroundColor Red 'The Azure AD account is DISABLED' $enablePrompt = Read-Host -Prompt 'Would you like to ENABLE this Azure AD account? (Y/N)' if ($enablePrompt -eq 'Y') { Set-AzureADUser -ObjectId $azureUser.ObjectId -AccountEnabled $true Write-Host -ForegroundColor Green 'Azure AD account has been successfully ENABLED' } else { Write-Host -ForegroundColor Yellow 'Azure AD account remains DISABLED' } } else { Write-Host -ForegroundColor Green 'The Azure AD account is ACTIVE' } } pause