Get-MsolUser : You must call the Connect-MsolService cmdlet

Get-MSOLUser You must call the Connect-MsolService cmdlet

When using the PowerShell command Get-MsolUser, you’ll sometimes see the error message “You must call the Connect-MsolService cmdlet before calling any other cmdlets”.

The output may be similar to this:

PS C:\> Get-MsolUser -UserPrincipalName morten@skrubbeltrang.onmicrosoft.com
Get-MsolUser : You must call the Connect-MsolService cmdlet before calling
   any other cmdlets.
   At line:1 char:1
+ Get-MsolUser -UserPrincipalName morten@skrubbeltrang.onmicrosoft.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Get-MsolUser],
    MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.
    MicrosoftOnlineException,Microsoft.Online.Administration.Automation.GetUser

This error message indicates that you have not established a connection to the Azure AD yet.

To fix this issue, you must connect using the Connect-MsolService command like this:

PS C:\> Connect-MsolService

(to see how to eliminate this type of issue once and for all, skip to the last section of this article)

This command will initiate the authentication process with Azure AD. The credentials you enter indicate what Azure AD Directory you’re connecting to:

Exchange Online Management MFA Signin

If the username and directory you entered are valid you’re requested to enter your password:

Exchange Online Management MFA Signin

If multi-factor authentication is enabled for your account you’ll be asked to enter the validation token:

Exchange Online Management MFA Signin

Once authenticated, you can rerun the Get-MsolUser command, and this time you should hopefully see the expected result:

PS C:\> Get-MsolUser -UserPrincipalName morten@skrubbeltrang.onmicrosoft.com
UserPrincipalName                    DisplayName          isLicensed
-----------------                    -----------          ----------
morten@skrubbeltrang.onmicrosoft.com morten skrubbeltrang True

The PowerShell MSOnline Module

The Get-MSOLUser command is part of the MSOnline PowerShell module.

In some cases, you can end up with multiple versions of the MSOnline module installed side by side. Troubleshooting which module is being loaded can be pretty confusing.

Also, in some cases, installing the module itself causes some headaches.

If you want to know more about the installation and troubleshooting of the MSOnline module, look at this article. It includes a full explanation of the module load order in PowerShell.

Easy Office 365 Management

To avoid this type of problem entirely, you should look at Easy365Manager.

Easy365Manager is an extension to the familiar AD Users & Computers tool.

With Easy365Manager, you can configure Office 365 licenses and mailboxes using your native on-premises AD user management tool. As a result, there is no need to constantly log in to the AD Azure portal and Exchange Admin Center.

Create an Office 365 mailbox using Easy365Manager

Easy365Manager also enables you to get rid of your on-premises Exchange Server. This allows you to save a lot of time and money in a short time frame.

Download the free and fully functional 30-day trial here.

Did you like this post? Maybe your friends will too!