logo exchange online

Ontbrekend @tenant.mail.onmicrosoft.com alias

Bij het opzetten van een hybride setup wordt automatisch een e-mail address policy aangepast om een @tenant.mail.onmicrosoft.com toe te voegen aan gebruikers. Echter kan het zijn dat je gebruikers hebt waarbij het vinkje is uitgezet om aliasen automatisch te genereren aan de hand van policies.

Draai het onderstaande script in Exchange Management Shell om mailboxen te identificeren waarbij het alias ontbreekt:

# Replace "tenant.mail.onmicrosoft.com" with the desired alias
$aliasToCheck = "tenant.mail.onmicrosoft.com"
$csvFilePath = "C:\beheer\UsersWithoutAlias.csv"

# Get all user mailboxes
$users = Get-Mailbox -ResultSize Unlimited

# Filter users without the specified alias and create a CSV file
$usersWithoutAlias = $users | Where-Object { $_.EmailAddresses -notcontains "smtp:$($_.Alias)@$aliasToCheck" }
$usersWithoutAlias | Select-Object DisplayName, Alias, EmailAddresses | Export-Csv -Path $csvFilePath -NoTypeInformation

Write-Host "CSV file created: $csvFilePath"

Pas de CSV file aan indien je sommige mailboxen handmatig van een alias wil voorzien:

# Import the CSV file and add the alias to each user
$usersToAddAlias = Import-Csv -Path $csvFilePath

foreach ($user in $usersToAddAlias) {
    $newAlias = "smtp:$($user.Alias)@$aliasToCheck"
    Set-Mailbox -Identity $user.Alias -EmailAddresses @{Add=$newAlias}
    Write-Host "Added alias $newAlias to $($user.DisplayName)"
}

Write-Host "Script completed."