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

Add homePhone Number to Contacts #69

Open yo-que-se opened 1 year ago

yo-que-se commented 1 year ago

Would it be possible to add the homePhone Number to the contact information of each contact? I need to sync 3 different phone numbers, but only is possible to sync 2 phone numbers.

Thank's in advance

christianneeb commented 1 year ago

I did add that to our scripts manually.

55

Edit Get-GALContacts.ps1 # If the ExcludeSharedMailboxContacts switch is enabled, exclude contacts that are a shared mailbox or mailbox with no liscense if ($ExcludeSharedMailboxContacts) { $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,HomePhone | Where-Object {$EmailAddressList.Contains($_.WindowsEmailAddress.ToLower())} } else { $ContactList = $ContactList | Select-Object DisplayName,FirstName,LastName,Title,Company,Department,WindowsEmailAddress,Phone,MobilePhone,HomePhone }

Edit Sync-Contactlist.ps1 Line 103 if ($null -eq $($MailboxContacts | Where-Object {(($_.GivenName -eq $Contact.FirstName) -or ("" -eq $Contact.FirstName)) -and (($_.Surname -eq $Contact.LastName) -or ("" -eq $Contact.LastName)) -and ($_.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].address -eq $Contact.WindowsEmailAddress) -and ($Contact.Company -eq $_.CompanyName -or $Contact.Company -eq "") -and ($Contact.Department -eq $_.Department -or $Contact.Department -eq "") -and (($_.DisplayName -eq $Contact.DisplayName) -or ($Contact.DisplayName -eq "")) -and ($Contact.Title -eq $_.JobTitle -or $Contact.Title -eq "") -and ($Contact.Phone -eq $_.PhoneNumbers[[Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::BusinessPhone] -or $Contact.Phone -eq "") -and ($Contact.MobilePhone -eq $_.PhoneNumbers[[Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::MobilePhone] -or $Contact.MobilePhone -eq "") -and (($Contact.HomePhone -eq $_.PhoneNumbers[[Microsoft.Exchange.WebServices.Data.PhoneNumberKey]::HomePhone]) -or ($Contact.HomePhone -eq "")) -and ($_.FileAs -eq $Contact.DisplayName)})) {

Line 134 New-EXCContactObject -MailboxName $Mailbox -DisplayName $Contact.DisplayName -FirstName $Contact.FirstName -LastName $Contact.LastName -EmailAddress $Contact.WindowsEmailAddress -CompanyName $Contact.Company -Department $Contact.Department -BusinssPhone $Contact.Phone -MobilePhone $Contact.MobilePhone -JobTitle $Contact.Title -FileAs $Contact.Displayname -Folder $ContactsFolderObject -useImpersonation -service $service

I also added the "FileAs" attribut in the sync to make sure the sorting in Outlook works as expected.

yo-que-se commented 1 year ago

Thanks a lot [christianneeb] !!!! Your code is working like a charm! Also i've implemented your solution for "Contact beeing excluded with -ExcludeSharedMailboxContacts if Emailaddress is in capital letters" and is working great!

Best regards.