"Connect-MsolService: Exception of type was thrown" when you use the connect-MSOLService to connect to Microsoft 365, Azure, or Intune

Problem

When you try to use the connect-MSOLService cmdlet in the Microsoft Azure Active Directory module for Windows PowerShell to connect to a Microsoft cloud service such as Microsoft 365, Azure, or Microsoft Intune, your attempt is unsuccessful. You may also receive the following error message:

Connect-MsolService: Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown.

Note

Azure AD Powershell is planned for deprecation on March 30, 2024. To learn more, read the deprecation update.

We recommend migrating to Microsoft Graph PowerShell to interact with Microsoft Entra ID (formerly Azure AD). Microsoft Graph PowerShell allows access to all Microsoft Graph APIs and is available on PowerShell 7. For answers to common migration queries, see the Migration FAQ.

Cause

This issue may occur for one or more of the following reasons:

  • The Azure Active Directory module for Windows PowerShell rich client can't connect to the service. This is frequently the result of client computer readiness issues.
  • The user ID that's used to authenticate is single sign-on (SSO)-enabled, and a client computer problem is preventing SSO communication with Active Directory Federation Services (AD FS), with the Microsoft Entra authentication system, or with both.

Solution

To resolve this issue, follow these steps:

  1. Troubleshoot Microsoft 365 rich client connectivity. For more information, see How to troubleshoot non-browser apps that can't sign in to Microsoft 365, Azure, or Intune.
  2. Troubleshoot common client configuration issues that limit SSO authentication. For more information, see Signing in to Microsoft 365, Azure, or Intune by using single sign-on doesn't work from some devices.

More information

For more information about Azure Active Directory module for Windows PowerShell, see Microsoft Entra Cmdlets.

Still need help? Go to Microsoft Community or Microsoft Entra Forums website.