Tuesday, October 9, 2012

Remove all secondary email addresses through powershell script

$Input = Get-Content C:\users.txt | Get-Mailbox
$Input | foreach {
write-host "$($_.Name) ---- $($_.EmailAddresses.Count)"
for ($i = $_.EmailAddresses.Count ;$i -ge 0; $i -- )
{
$_.EmailAddresses[$i].ProxyAddressString  
if ($_.EmailAddresses[$i].IsPrimaryAddress  -eq $false )
{
$_.EmailAddresses.RemoveAt($i)

}
  set-mailbox  $_.Identity -EmailAddresses $_.EmailAdresses
}

No comments:

Post a Comment