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

Not working with error message #47

Open nldenic opened 2 years ago

nldenic commented 2 years ago

Dear,

I have follow the steps but still geting an error:

  1. create an .cred file for my admin account.
  2. Create an bat file with following rules: @echo off cd "%~dp0EWS-Office365-Contact-Sync"

PowerShell.exe -ExecutionPolicy Bypass ^ -File "C:\Users\cade\Desktop\EWS-Office365-Contact-Sync-master\EWSContactSync.ps1" ^ -CredentialPath "C:\temp\caglar.cred" ^ -FolderName "TEST Caglar" ^ name for the outlook contact folder. This folder does not exist. So it will create by it self on the user contact folder ? -LogPath "%~dp0Logs" ^ -MailboxList icttest@.....,nl ^ -ModernAuth pause

VERBOSE: Loading module from path 'C:\Users\cade\Desktop\EWS-Office365-Contact-Sync-master\EWSContacts\Module\bin\Microsoft.Exchange.WebServices.dll'.

TerminatingError(Import-Module): "Could not load file or assembly 'file:///C:\Users\cade\Desktop\EWS-Office365-Contact-Sync-master\EWSContacts\Module\bin\Microsoft.Exchange.WebServices.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"

nldenic commented 2 years ago

i have also unlbock de dll files. now see this error: A constructor was not found. Cannot find an appropriate constructor for type Microsoft.Exchange.WebServices.Data.OAuthCredentials.

grahamr975 commented 2 years ago

Did you also unblock the Microsoft.IdentityModel.Clients.ActiveDirectory.dll file? Is EWS 2.2 installed on the computer? Please refer to the getting started documentation in the README.

nldenic commented 2 years ago

Dear i did unblock the dll. I don't have ews installed in my laptop 😁. Do you have an link to download? Current link is not working.

grahamr975 commented 2 years ago

I can't 100% vouch for this link, but looks like someone reuploaded the install here: https://github.com/gangstanthony/PowerShell/blob/master/EWSManagedAPI2.2.msi

I found it from the Reddit thread below https://www.reddit.com/r/exchangeserver/comments/o9jy3y/looking_for_ewsmanagedapimsi/

nldenic commented 2 years ago

Thank you i will check. Else i will add it like an app in Azure.

Maybe its good to do that. Maybe you can write also that in your Readme how to add as azure App.

I think most People will use it. Its just an better and good alternative for Cirasync or Galsync.

Do you also do this aşk schedule task every week?

grahamr975 commented 2 years ago

@nldenic

I think you may be confused about what the Azure app does. Even if you set up an app for this script in Azure, you'll still need to install EWS API 2.2 on the host computer. If you're referring to issue #46, the purpose of the Azure app, in that case, is to circumvent the need for multi-factor authentication.

Personally, I use Windows Task Scheduler to run the script every day.

nldenic commented 2 years ago

Thank you i will install that also and let see if thats works.

It will realy be nice if it works in azure without EWS.

Like this option https://practical365.com/prepopulating-outlook-contacts-with-the-graph-api/

Do you think your script will work with gpah api?

nldenic commented 2 years ago

@grahamr975

I have now do the following steps: Installed EWS 2.2 on my laptop export my Exchange online admin credentials to an Cred file. Created an bat file with following parrameters : cd "%~dp0EWS-Office365-Contact-Sync" PowerShell.exe -ExecutionPolicy Bypass ^ -File "C:\Users\%username%\Desktop\EWS-Office365-Contact-Sync-master\EWSContactSync.ps1" ^ -CredentialPath "C:\Users\%username%\Desktop\EWS-Office365-Contact-Sync-master\nldenic.cred" ^ -FolderName "TEST-Contacts" ^ -LogPath "%~dp0Logs" ^ -MailboxList icttest@ourdomain.nl ^ -ExcludeSharedMailboxContact ^ -ExcludeContactsWithoutPhoneNumber ^ -ModernAuth ^ pause

Still gettings : ERROR Failed to Sync-ContactList for icttest@ourdomain.nl A constructor was not found. Cannot find an appropriate constructor for type Microsoft.Exchange.WebServices.Data.OAuthCredentials.

I have try to disable MFA for my Admin account and run it. But still not working for it.

AD Azure shows me this for my account : image image

Do you see other issue for this ?

nldenic commented 2 years ago

@grahamr975 The problem looks solves for the normal method.

So i have delete -ModernAuth ^ and run my bat file again.

It is working. But does that means my admin account does not have mfa? Because it has mfa active 😁

In the meantime i am still gettinng error for the Azure sollution.

It will be great if you can write the Azure sollution as option.

See also my other qustion #46

grahamr975 commented 2 years ago

@nldenic if the script works without -ModernAuth, that means basic authentication is still enabled within your environment. In order for modern auth to work, you'll need to bypass MFA for the script by trusting the IP of the server you're running the script on. See Microsoft's guide below.

https://docs.microsoft.com/en-us/azure/active-directory/authentication/howto-mfa-adfs#trusted-ips-for-federated-users

nldenic commented 2 years ago

@nldenic if the script works without -ModernAuth, that means basic authentication is still enabled within your environment. In order for modern auth to work, you'll need to bypass MFA for the script by trusting the IP of the server you're running the script on. See Microsoft's guide below.

https://docs.microsoft.com/en-us/azure/active-directory/authentication/howto-mfa-adfs#trusted-ips-for-federated-users

Thats correct. For now its working on my account with basicauth. Enabled.

For now this is ok but do you think its simple to make this work with azure api connection? For my its not working yet and get error message see other issue i mention the script there.

grahamr975 commented 2 years ago

@nldenic

If you mean changing the script to not use EWS and only using Azure (Graph API), that would require a rewrite of the majority of the script. It's in the pipeline but not coming soon, since those changes will take time to develop and test.

nldenic commented 2 years ago

@grahamr975

For now its working on my on-premise server without the -ModernAuth because this is enabled. For now i am just working on it to let it work with modernauth and using certificate.