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

FeatureRequest: Limit Sync to UserMailbox #36

Open mnefk opened 3 years ago

mnefk commented 3 years ago

Hi

i tried to find a way to limit the Sync applied to only UserMailboxes without Resource or Shared-Mailboxes.

Normaly this whould be like "Get-Mailbox -RecipientTypeDetails UserMailbox" But this is of course not possible at the Get-Mailboxes -Connect... command if used "DIRECTORY".

# If 'DIRECTORY' is used for $MailboxList, fetch all Mailboxes from the administrator account's Office 365 directory if ($MailboxList -eq "DIRECTORY") { $MailboxList = Get-Mailboxes -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credentials $Credential }

Is it possible you add a "filter" like this to only apply to almost "real users"? Regards and thank you very much for your engagement with this great script!

grahamr975 commented 3 years ago

Can you try using the ExcludeSharedMailboxContacts flag? See a list of all options here: https://github.com/grahamr975/EWS-Office365-Contact-Sync/blob/40d8a41cf3702196aeeb33118398b1698366a9f4/EWSContactSync.ps1

PowerShell.exe -ExecutionPolicy Bypass ^
-File "%CD%\Multi-Import.ps1" ^
-CredentialPath "%CD%\Tools\SecureCredential.cred" ^
-FolderName "My Contact Folder" ^
-LogPath "%CD%\Logs\%mydate%_%mytime%.log" ^
-MailboxList "DIRECTORY" ^
-ExcludeSharedMailboxContacts
mnefk commented 3 years ago

I have, but thats for the content (what will be synced, Source) and not the target for the sync

My configuration so far:

PowerShell.exe -ExecutionPolicy Bypass ^ -File "%CD%\EWSContactSync.ps1" ^ -MailboxList DIRECTORY ^ -CredentialPath "%CD%\credentials.xml" ^ -FolderName "Mitarbeiter" ^ -LogPath "%CD%\Logs\%mydate%_%mytime%" ^ -ExcludeSharedMailboxContacts ^ -ExcludeContactsWithoutPhoneNumber ^ -ModernAuth

rypto commented 3 years ago

If you run a ps1 script with the following strings, you can add several mailboxes..

cd C:\scripts\EWS-Office365-Contact-Sync-master Set-ExecutionPolicy -ExecutionPolicy Bypass .\EWSContactSync.ps1 -CredentialPath "C:\scripts\EWS-Office365-Contact-Sync-master\cred.cred" -FolderName "Corporate Contacts" -LogPath "C:\scripts\EWS-Office365-Contact-Sync-master\Logs" -MailboxList "user1@domain.com", "user2@domain.com", "user3@domain.com"

mtrojacher commented 1 year ago

This can be done by updating line 41 of Get-Mailboxes.ps1 to read $DirectoryList = $(Get-Mailbox -ResultSize unlimited -RecipientTypeDetails UserMailbox | Where-Object {$_.HiddenFromAddressListsEnabled -Match "False"}).PrimarySMTPAddress