Bulk Change UPN for Users to .onmicrosoft.com for Domain Renewal via Powershell for Cloud only Users in Azure AD

Connect-AzureAD

# Define old and new domains
$oldDomain = "domain.com.au"
$newDomain = "cfch2020.onmicrosoft.com"

# Get all users with the old domain in their UPN
$users = Get-AzureADUser -All $true | Where-Object { $_.UserPrincipalName -like "*@$oldDomain" }

foreach ($user in $users) {
    # Construct the new UPN
    $newUPN = $user.UserPrincipalName -replace "@$oldDomain", "@$newDomain"

    # Update the user's UPN
    Write-Host "Updating UPN for $($user.UserPrincipalName) to $newUPN"
    Set-AzureADUser -ObjectId $user.ObjectId -UserPrincipalName $newUPN
}

Write-Host "UPN update completed."

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...