The Exchange Online PowerShell V2 module (abbreviated as the EXO V2 module) uses modern authentication and works with multi-factor authentication (MFA) for connecting to all Exchange-related PowerShell environments in Microsoft 365: Exchange Online PowerShell, Security & Compliance PowerShell, and standalone Exchange Online Protection (EOP) PowerShell.
using modern authentication:
Prerequisites
- First you need to download the EXO V2 . You can download the module from the PowerShell gallery at https://www.powershellgallery.com/packages/ExchangeOnlineManagement/.
- Windows PowerShell needs to be configured to run scripts, and by default, it isn’t. You’ll get the following error when you try to connect: “Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files”.
- run the following command in an elevated Windows PowerShell (Run As Administrator)
Set-ExecutionPolicy RemoteSigned
- WinRM needs to allow Basic authentication
To verify that Basic authentication is enabled for WinRM, run this
command in a Command Prompt (not in Windows PowerShell):
winrm get winrm/config/client/auth
If you don’t see the value Basic = true, you need to run this command in a Command Prompt (not in Windows PowerShell) to enable Basic authentication for WinRM:
winrm set winrm/config/client/auth @{Basic=”true”}
INSTALL EXO V2 Module
- Install or update the PowerShellGet module
Install-Module -Name PowerShellGet -Force // PS 5
Install-PackageProvider -Name NuGet -Force // PS 4
- Install the EXO
Install-Module -Name ExchangeOnlineManagement
Connect to Exchange Online PowerShell using MFA and modern authentication
For MFA authentication Run :
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName
Connect to Exchange Online PowerShell using modern authentication
For Modern Only authentication Run :
Import-Module ExchangeOnlineManagement
$UserCredential = Get-Credential
Connect-ExchangeOnline -Credential $UserCredential
SHMUEL H.