Add an alias to multiple users in 365

Adding an alias to multiple users in 365.  in the example below, all users that have a primary SMTP address that matches nsw.anonit.net will have the $($user.alias)@qld.anonit.net alias added.

Eg:

john.smith@nsw.anonit.net will have john.smith@qld.anonit.net alias added, whereas, jane.doe@vic.anonit.net will not have any alias added.

$users = Get-Mailbox | Where-Object{$_.PrimarySMTPAddress -match "nsw.anonit.net"}

foreach($user in $users){

    Write-Host "Adding Alias $($user.alias)@qld.anonit.net"

    Set-Mailbox $user.PrimarySmtpAddress -EmailAddresses @{add="$($user.Alias)@qld.anonit.net"}

}

Leave a Reply

Your email address will not be published. Required fields are marked *