Powershell Logo

Connect to Exchange Online Powershell

Todays post is simple. It gives you different ways to connect to Exchange Online Powershell 👍

The issue:

There are many ways to connect to Exchange Online Powershell, none I find give a definitive guide on each method.

The resolution:

These ways are:

1: The normal admin access way if you dont have MFA enabled.

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Connect to Exchange Online Powershell

2: Delegate Admin: Covered in another post, great for people that manage more than one tenancy.

Connect to Exchange Online Powershell3: Via a function:

Save the function:

Function Connect-EXOnline{

$credentials = Get-Credential -Credential youremail@yourdomain.com
Write-Output “Getting the Exchange Online cmdlets”

$Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-ConfigurationName Microsoft.Exchange -Credential $credentials `
-Authentication Basic -AllowRedirection
Import-PSSession $Session

}

Now just type in “Connect-EXOnline”.  This will call the function, ask for your username and password and your’e connected!

Connect to Exchange Online Powershell

4: If you have MFA enabled on your account:

$CreateEXOPSSession = (Get-ChildItem -Path $env:userprofile -Filter CreateExoPSSession.ps1 -Recurse -ErrorAction SilentlyContinue -Force | Select -Last 1).DirectoryName

. “$CreateEXOPSSession\CreateExoPSSession.ps1”

Connect-EXOPSSession -UserPrincipalName youremail@yourdomain.com

This calls upon the M365 Window to pop in your password which in turn, gives your the MFA notification/code popup.

Connect to Exchange Online Powershell

5: The latest way to connect, is also great if you have MFA enabled:

Connect-exchangeonline -userprinciplename “youremail@yourdomain.com”

Perloads all the modules for you and gives you a list of old and new cmdlets like the delegated admin does:

Connect to Exchange Online Powershell

Prerequisites can be found here, for anything else please feel free to get in touch. 👍