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:
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:
This command will initiate the authentication process with Azure AD. The credentials you enter indicate what Azure AD Directory you’re connecting to:
If the username and directory you entered are valid you’re requested to enter your password:
If multi factor authentication is enabled for your account you’ll be asked to enter the validation token:
Once authenticated you can run the Get-MsolUser command again, and this time you should hopefully see the expected result:
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.