When you migrate to Office 365 from local AD, and keep a hybrid environment,  you probably need to add proxyAddresses to all of  AD users so that you can change my MX records.

The below script will help you to add multiple records, such as SamAccountName@domain.name

 

Get-ADUser -Filter * -SearchBase "OU=2024,OU=Students,OU=DC=domain,DC=name" | foreach-object {

    $Proxies = @("SMTP:$($_.sAMAccountName)@domain.name")

    $Proxies += "smtp:$($_.givenname).$($_.surname)@domain.name"

    $Proxies += "smtp:$($_.sAMAccountName)@domainname.mail.onmicrosoft.com"

    $Proxies += "smtp:$($_.sAMAccountName)@domainname.onmicrosoft.com"

    $_ | Set-ADuser  -Replace @{ProxyAddresses = $Proxies}

}