Connecting to Exchange Online via PowerShell offers more administrative control than you otherwise have available in the web interface. It's very useful for bulk changes, automation and situations where finer administrative control is required.

The Exchange Online PowerShell module is the easiest way to connect to your instance. It has built-in support for MFA so you don't need to generate an app password to interact and prevents non MFA credentials from leaking. To get working with the Exchange Online PowerShell module follow the steps below:

Install the Exchange Online PowerShell Module:

  1. Open https://admin.microsoft.com
  2. Click 'Admin Centers'
  3. Click 'Exchange' on the left
  4. Click 'hybrid' on the left
  5. Click 'configure' under '…Exchange Online PowerShell Module supports…'
  6. Install the module

Connect to your instance:

  1. Open the 'Exchange Online PowerShell Module'
  2. Run the following command to connect:
Connect-EXOPSSession -UserPrincipalName <365 Username>

3.   Login to the prompt

4.   Check if you can successfully query your instance by listing any available mailbox's:

Get-Mailbox

Sources:
https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps