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.

Before retrieving or setting information in Azure AD you must connect using the Connect-MsolService command like this:

PS C:\> Connect-MsolService

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 run the Get-MsolUser command again, 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 quite confusing.

Also, in some cases, the installation of the module itself causes some headache.

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

Easy Office 365 Management

To skip the need to use the MSOnline PowerShell module entirely during daily administration, you should have a look at Easy365Manager.

Easy365Manager works as an extension to the familiar AD Users & Computers tool. With Easy365Manager you can configure Office 365 licenses and mailboxes using your native on-premise AD user management tool. No need to constantly log in to the AD Azure portal and Exchange Admin Center.

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!