Tag Archives: Powershell Exchange

Delete one email address from all contacts in one OU

get-mailcontact -OrganizationalUnit "contoso.com/path/to/ou" |
foreach { 
   $a = $_.emailaddresses
   $b = $_.emailaddresses
   
   foreach($e in $a) 
       { 
           if ($e.tostring() -match "@emailtoremove.com") 
               { $b -= $e; } 
           } 
       $_ | Set-mailContact -emailaddresses $b } -whatif }