Wednesday 2 July 2014

Script to update email address

$all = Import-Csv C:\temp\test.csv

foreach($a in $all)
{
  $addr = (get-recipient $a.PrimaryEmail).EmailAddresses

  $temp1 = "smtp:" + $a.NewEmail

  $newaddr = $addr + $temp1

  Set-Mailbox $a.PrimaryEmail -EmailAddresses $newaddr
}



Notes:

In the test.csv there are two columns (PrimaryEmail & NewEmail)
.EmailAddresses is a property and this can be checked by running a command Get-Recipient | Get-member
If you want to make the new email as Primary SMTP address then replace "smtp:" with "SMTP:"


No comments:

Post a Comment