Teste isso em um laboratório e / ou em um pequeno conjunto de usuários de teste antes de iniciar a produção com isso.
$SMTPDomainToRemove = "@OldDomain.com"
$AllUsers = Get-ADUser -Filter * -Properties proxyAddresses
Foreach($usr In $AllUsers)
{
$NewAddressList = @()
$OldAddressList = $usr.proxyAddresses
Foreach($addr In $OldAddressList)
{
If(!($addr -Match $SMTPDomainToRemove))
{
$NewAddressList += $addr
}
}
If($NewAddressList.Count -GT 0)
{
Set-ADUser $usr -Replace @{ 'proxyAddresses' = $NewAddressList}
}
}
A idéia é que estamos pegando a lista de endereços proxyAddresses de cada usuário, removendo aqueles que possuem o antigo nome de domínio, e então substituindo a lista de endereços pela nova e atualizada, que não contém referências a o antigo nome de domínio.
link
E-Mail Address Attributes
Exchange stores and uses information about the e-mail addresses of a
recipient in the following attributes: proxyAddresses
This is the main attribute where e-mail address information is kept.
When you open the properties of a recipient in Outlook and look at the
"E-mail Addresses" tab, you are looking at this attribute. This is a
multi-valued string containing all the addresses that represent the
recipient. Each value must have the following format: type:address
For example: SMTP:[email protected]
When the type is in uppercase letters, the address is considered to be
the primary address of that type and it is used as the default reply
address of that recipient. When the type is in lowercase letters, the
address is considered a secondary address and is used to resolve
addresses during e-mail delivery, allowing the same recipient to
receive e-mails directed to different e-mail addresses.