The Exchange Online PowerShell module uses modern authentication and works with multi-factor authentication (MFA). This module can be used to connect and manage Exchange-related resources in Microsoft 365 such as user mailbox, calendar, etc.
Install the Exchange Online PowerShell module
Open your PowerShell with Run as administrator privilege. Run the following command to install the latest Exchange Online PowerShell if you have not already installed it.
Install-Module -Name ExchangeOnlineManagement
Connect the Exchange Online module
Once you successfully installed the module, run the following command and provide your user credentials to your Exchange environment.
Connect-ExchangeOnline
#The specified UPN value used on the login page
Connect-ExchangeOnline -UserPrincipalName "[email protected]"
Use PowerShell Cmdlets with Exchange Online
Once you have connected the Exchange Online PowerShell module, you can now run all the available cmdlets. Let’s start with a simple cmdlet:
Get-Mailbox
-or-
Get-ExoMailbox
The above cmdlet lists all Microsoft 365 mailboxes.
Disconnect PowerShell Session
Once you have completed all the work, disconnect the PowerShell session. Run the following command to disconnect the remote PowerShell session.
Disconnect-ExchangeOnline
Note: If you are new to PowerShell, don’t forget to set your execution policy to unrestricted or you might get an error when you try to run a script that is downloaded from the internet.
Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files.
Use the below command to set your execution policy:
Set-ExecutionPolicy RemoteSigned