Forum Discussion
Task Scheduler to connect to Exchange Online Powershell using MFA
Thanks Vasil. However as I understand, -Userprincipalname is a mandatory parameter, i cannot skip it. I have tried using
# Enter credential in format user@domain.com
$cred = Get-Credential
Connect-EXOPSSession -Credential $cred
But this fails
New-ExoPSSession : user_realm_discovery_failed: User realm discovery failed
It's not mandatory anymore, make sure you update your ExO module.
- ashaikhMar 28, 2018Copper Contributor
I went to Office 365 exchange admin center => hybrid
For exchange online powershell module, clicked on configure
then opened the shortcut to Microsoft Exchange Online Powershell Module from desktop
typed the following;
$cred = Get-credential ( Entered credential in the format user@domain.com)
Connect-EXOPSSession -Credential $cred
New-ExoPSSession : wstrust_endpoint_not_found: WS-Trust endpoint not found in metadata document
At C:\Users\<username>\AppData\Local\Apps\2.0\XOB1V3KL.06M\82LDHNN9.8KN\micr..tion_a8dgft24shidhnb0c4a7_0010.0000_46a3c55dd9dd5128\CreateExoP
SSession.ps1:187 char:22
+ ... PSSession = New-ExoPSSession -UserPrincipalName $UserPrincipalName -C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AdalException
+ FullyQualifiedErrorId : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException,Microsoft.Exchange.Management.ExoPowershe
llSnapin.NewExoPSSession- VasilMichevMar 28, 2018MVP
That error indicates an issue on MS side, best open a support case. The module works just fine with -Credentials:
- JeremyTBradshawFeb 10, 2019Iron Contributor
-Credential only works if you don't have MFA enabled. For those that do, this is what happens:
>Connect-EXOPSSession -credential (Get-Credential user@tenant.onmicrosoft.com)
New-ExoPSSession : AADSTS50076: Due to a configuration change made by your administrator, or
because you moved to a new location, you must use multi-factor authentication to access
'00000002-0000-0ff1-ce00-000000000000'.
Trace ID: 0447ae7b-0eb7-458a-b479-c73b66af5700
Correlation ID: 5a85f56a-8468-4ca3-9739-95496153e12a
Timestamp: 2019-02-10 13:16:30Z
At C:\Users\jerem\AppData\Local\Apps\2.0\BRCQW4A8.VAY\HBOMCBME.APA\micr..tion_1975b8453054a2b5_0010
.0000_10d85008035862c6\CreateExoPSSession.ps1:292 char:30
+ ... PSSession = New-ExoPSSession -UserPrincipalName $UserPrincipalName.Va ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AdalServiceException
+ FullyQualifiedErrorId : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException
,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession