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

Fix for Modernauth -ExcludeSharedMailboxContacts #58

Closed Snake98bm closed 1 year ago

Snake98bm commented 1 year ago

After applying the fix from JimSnead here

https://github.com/grahamr975/EWS-Office365-Contact-Sync/issues/56#issuecomment-1198509331

I couldn't use the -ExcludeSharedMailboxContacts flag. Here is orginal code from JimSnead

        $DirectoryList = $(Get-EXOMailbox -ResultSize unlimited | Where-Object {$_.HiddenFromAddressListsEnabled -Match "False"})

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

Here is the fix for the code.

        $DirectoryList = $(Get-EXOMailbox -ResultSize unlimited -PropertySets Minimum,AddressList | Where-Object {$_.HiddenFromAddressListsEnabled -Match "False"})

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

Sorry couldn't do a pull request.

grahamr975 commented 1 year ago

@Snake98bm thanks for posting this

grahamr975 commented 1 year ago

@Snake98bm

I applied this fix along with the OAuth upgrade in commit 9fcfe1f06192848882564615dd9aa05e71d69970. Please reach out if you have any questions.