简体   繁体   中英

Exchange Powershell - Bulk add new SMTP address to all mailbox users

Exchange Server 2007

I need to run a command across all mailboxes to insert a new SMTP address to each mailbox. Easy enough to run a Get-MailContact to add new addresses if they are all the same format. Such as FirstName+"."+.LastName at the domain. However, not all SMTP addresses follow this convention.

We have some addresses that are, for example: john.doe@domain.com , jane.l.smith@domain.com and jsmith@domain.com .

I need to keep those existing smtp addresses but add a new smtp address with a new domain and keep the prefix format. So, I need to add john.doe@newdomain.com , jane.l.smith@newdomain.com , and jsmith@newdomain.com to the those three mailboxes.

I'm just not sure how to scan all the mailboxes for any address that contains *@domain.com and add *@newdomain.com

What can I do here?

Something like this should work, but I haven't tested it, so I would definitely test it against a test environment before destroying your exchange server...

$NeedsNew = get-mailbox -ResultSize Unlimited | Where-Object { $_.EmailAddresses -like "*@domain.com"
foreach ( $Mailbox in $NeedsNew ) {
    $EmailAddresses = $Mailbox.EmailAddresses
    $Changed = $false
    foreach ( $Address in $EmailAddresses ) {
        if ( $Address -like "*@domain.com" ) {
            ( $prefix, $oldDomain ) = $Address.AddressString.split("@")
            $EmailAddresses += "{0}@newdomain.com" -f $prefix
            $Changed = $true
        }
    }
    if( $Changed ) {
        Set-Mailbox -Identity $Mailbox -EmailAddresses $EmailAddresses
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM