Issues with Connect-ExchangeOnline cmdlet in Powershell 5

Mark Lee 0 Reputation points
2023-12-04T05:55:58.3+00:00

Hi all,

I'm having issues with the Connect-ExchangeOnline cmdlet using EXO v3.4.0

The issue started occurring after the deprecation of EXO v2, and after we swapped to EXO v3.

Our script is designed to run unattended, and the credentials of the service account used for the login is grabbed automatically from a safe.

The issue we are experiencing is, trying to run the command 'Connect-ExchangeOnline -Credential $creds'

This gives the error - 'An error occurred while sending the request'

Using -Verbose just shows an extra line 'ConnectionContext: Removed'

The strange thing is, trying to connect via 'Connect-ExchangeOnline -UserPrincipalName example@example.com' which then brings up an external login window works after entering the password. The banner text successfully shows and the connection works fine. However we can't utilize this method as the script is designed to run automatically.

Even stranger, after successfully connecting via the above, the previous 'Connect-ExchangeOnline -Credential $creds' command works perfectly fine.

Can anyone provide help on this?

Also just a note: This connection works perfectly fine on our test environment server with the same setup, using the -Credential $creds parameter with no additional input needed

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,894 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,951 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    3 deleted comments

    Comments have been turned off. Learn more

  2. Anonymous
    2023-12-07T08:52:26.4166667+00:00

    Hello @Mark Lee

    <<They have the same configuration using the same script. Same OS version, same module version.The issue started occurring after the deprecation of EXO v2, and after we swapped to EXO v3.

    Completely understand. this is indeed strange. Perhaps you have already confirmed that they are the same module versions, but we would appreciate it if you could kindly confirm it again for us. Please use the following command to check if the specific versions in the two environments are the same.

    Get-InstalledModule ExchangeOnlineManagement | Format-List Name,Version,InstalledLocation

    <<The thread you have linked suggests to set up certification authentication

    Also, as a MS representative, I hope you will also consider using the official method.

    Regards

    SF


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.