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 }
Advertisements

One thought on “Delete one email address from all contacts in one OU

  1. MannyEX

    Get-MailContact | Set-MailContact -EmailAddressPolicyEnabled: $false
    $MailContacts = Get-MailContact
    $MailContacts | foreach {$contact = $_; $email = $contact.emailaddresses;
    $email | foreach {if ($_.smtpaddress -like “*@contoso*”) {$address = $_.smtpaddress;
    write-host “Removing address” $address “from Contact” $contact.name;
    Set-Mailcontact -Identity $contact.identity -EmailAddresses @{Remove=$address}}}}

    Like

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s