How to connect to Microsoft 365 using PowerShell and MFA
If a user with Multi Factor Authentication (MFA) enabled tries to connect to his M365 tenant via PowerShell, the Connect-MsolService command cannot be used because it only displays a classic login field with username and password.
However, for some tasks and commands, we need to log in with Connect-MsolService first in order to execute other commands.
You must be a tenant administrator (i.e. comany administrator, global administrator) to successfully establish a connection to your Microsoft 365 tenant using PowerShell. Read here how to assign an admin role in Office 365.
Make sure that you have already installed the MSOnline module or install it once with the following command:
Install-Module -Name MSOnline
Confirm the prompts by typing Y (yes) or A (all).
You’re now ready to connect to your Microsoft 365 tenant using PowerShell!
- To do so, run the Windows PowerShell console as administrator
- Enter the following PowerShell commands:
Import-Module MsOnline
Connect-MsolService - A Microsoft 365 prompt windows opens where you enter your M365 admin credentials.
You’re all set. Start managing your Microsoft 365 tenant using this great overview of the Azure AD cmdlets.