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
96 stars 21 forks source link

Attributes cant be found #35

Closed Backmischung closed 2 years ago

Backmischung commented 3 years ago

Hello Ryan,

first of all, thanks for the great Code.

I´m getting following message when i try to run your script for some users: 2021.03.03 16:15:38 INFO Updating Contact: firstname.surname@company.de 2021.03.03 16:15:38 ERROR Failed to sync firstname.surname@company.de contact to firstname2.surname2@company.de's mailbox Die Eigenschaft "GivenName" wurde für dieses Objekt nicht gefunden. Vergewissern Sie sich, dass die Eigenschaft vorhanden ist und festgelegt werden kann. (The Attribute "givenname" wasn´t found for this object. Check if the attribute exists and can be allocated.) this may derive a little from my translation, but basically that.

The tricky part seems to be, that those contacts can be synched to most of the mailboxes.

Maybe you could give me a hint where to look for the missing configuration or why it wouldnt find those attributes.

Best regards Adrian

grahamr975 commented 3 years ago

@Backmischung,

I hope you're doing well.

I'm able to replicate this issue in my own environment. Specific contacts produce the "GivenName" error, but not to all mailboxes.

2021/03/02 16:40:12 INFO Updating Contact: john.doe@mycompany.com
PS>TerminatingError(Set-EXCContactObject): "The property 'GivenName' cannot be found on this object. Verify that the property exists and can be set."
2021/03/02 16:40:13 ERROR Failed to sync john.doe@mycompany.com contact to jane.doe@mycompany.com's mailbox The property 'GivenName' cannot be found on this object. Verify that the property exists and can be set.

GivenName is one of the properties of the Contact EWS class. You can find more info here: https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.contact?view=exchange-ews-api

Since (in my experience) the error only occurs when updating contacts, we know that we're dealing with contact objects fetched from a user's mailbox. You can see the line below from Sync-ContactList.ps1. $MailboxContacts = Get-EXCContactsObject -MailboxName $Mailbox -Credentials $Credential -Folder $ContactsFolderObject -service $service | Where-Object {$null -ne $_.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].Address}

I'll need to do some testing. Unfortunately, I've been busy with other projects and will need some time to come back to this.

Backmischung commented 3 years ago

Hello again,

just a little update: the error kept persisting but deleting the created folder and initiating a new sync solved the issue (as expected).

A way to remotely deleting the created folder would be a nice tool for troubleshooting in general.

Best regards Adrian

Backmischung commented 3 years ago

Update: The same error keeps occuring. Deleting the synced folder is just a temporary solution, also hard to keep up with multiple mailboxes.

wayfarerfin commented 3 years ago

I had same issue with update function, but i noticed it only happens if there is duplicate contact on destination folder.

wayfarerfin commented 3 years ago

I just added following if before set-exccontactobject. It's not pretty, but does following and doesn't crash to "Given name" error.

If more than one contact found with same email addres, this picks first one and deletes it and update second one.

For some reason it just delete on first run and update on second run. But without "$ContactObject = $result2" job crashes. So, it's not pretty and may need tweaking, but working its own ugly way ;)

edit. Replaced - first 2 to - last 1 😉


write-host "Contact count on contacts folder with same email address $kontaktiwindowsemailaddress :" $ContactObject.count

Delete if double"

if ($ContactObject.Count -gt 1){

$result = $ContactObject | select-object -first 1

$result2 = $ContactObject | select-object -last 1

write-host "Duplicate found, deleting $result"

$result.Delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::SoftDelete)

$ContactObject = $result2

}

try {

Set-EXCContactObject -MailboxName $Ma....

grahamr975 commented 2 years ago

@wayfarerfin Thanks for explaining this issue and writing out some sample code to fix it. I just addressed this in the last commit 7cb0b305a339ed088df4a320fc0aac0caee64459. Please update and see the changelog for more information.