0
votes

I use contact groups with members from a contact list.

Whenever a contact in the contact list is deleted, this previously-added member still exists in the contact group until I hit "update now" in Outlook where the contact group is open for editing. Then a pop-up comes up asking whether I want to delete the no-longer-existing member.

Since I use multiple contact groups I do not want to update each of them individually but with a background job based on the EWS managed API. Thus far I have managed to select each contact group, display members' email addresses, but I do not know how to accomplish this "update now" button-function of outlook! The ordinary update method with AlwaysOverwrite works, but does not do what I want: delete the nonexistent contacts.

(By the way, the contact groups / contact lists reside in public folders.)

2

2 Answers

0
votes

EWS doesn't expose that functionality. Essentially, Outlook tries to retrieve the contact by Entry ID, and when it fails, it prompts you to remove it. You could implement something similar (get each email address, try to resolve it back to a contact, etc).

0
votes
## $service excahnge service referend
## $folder .. ExchangeFolder where group and contacts are 
## $group ... instance of contact group

$members = $service.ExpandGroup($group.id)
for($l=0;$l -lt $members.members.count;$l++) {
    $curMember = $members.members[$l]
    $objViewUser =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(1)
    $curEmail = $members.members[$l].address
    ## check if there still exists a contact with this email-address
    $searchFilterEA1 = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ContactSchema]::EmailAddress1,$curEmail)
    $resultContact = $folder.FindItems($searchFilterEA1,$objViewUser).Items.Count
    if ($resultContact -eq 0) {
       "delete Contact $curEmail"
        ???????
        }
    }
}