grahamr975 / EWS-Office365-Contact-Sync

Uses Exchange Web Services to synchronize a Global Address List in Office 365 to a user's mailbox
MIT License
94 stars 21 forks source link

ExcludeSharedMailboxContacts excluding many (real) Users #80

Closed Robs90 closed 1 year ago

Robs90 commented 1 year ago

When using the Parameter ExcludeSharedMailboxContacts, some Users get excluded even though they are returned by Get-EXOMailbox and are present in the Variable $Contactlist.

We found that the comparison between the results of Get-EXOMailbox and $Contactlist is Case sensitive. This results in excluding a User, when the WindowsEmailAddress is written using Capital Letters (First.Lastname@Domain.com) and the PrimarySMTPAddress is written in lower Case (first.lastname@domain.com). The script does not see a Match, and this User is skipped in the Contact List.

We found that when using the parameter ExcludeSharedMailboxContacts, the following line (Line 66 of Get-GALContacts.ps1) should be changed:

OLD (skipping Users where the Case does not match):

$ContactList = $ContactList | Select-Object DisplayName,FirstName,LastName,Title,Company,Department,WindowsEmailAddress,Phone,MobilePhone | Where-Object {$EmailAddressList.Contains($.WindowsEmailAddress)}

NEW (which ignores the Case in which the Emailaddress is written):

$ContactList = $ContactList | Select-Object DisplayName,FirstName,LastName,Title,Company,Department,WindowsEmailAddress,Phone,MobilePhone | Where-Object {$EmailAddressList -Contains $.WindowsEmailAddress}

Using the Contains Parameter in the second format, is not Case Sensitive. The Functionality however stays the same.

grahamr975 commented 1 year ago

@Robs90

Thanks for the detailed breakdown. This logic makes sense. When I have time, I will test and push this commit.

Ryan

koreytm commented 1 year ago

Great find, @Robs90 !

christianneeb commented 1 year ago

Same issue was posted about a year ago incl another solution but yours looks cleaner :)

55 Contact beeing excluded with -ExcludeSharedMailboxContacts if Emailaddress is in capital letters

grahamr975 commented 1 year ago

Addressed by latest commit...