The web UI for Office 365/Exchange Online is great, and getting better all the time – but there are still many settings and functions which can only be interacted with via Exchange Online Powershell. The exact process differs on whether or not MFA is enabled (with Modern Authentication), so we’ll briefly cover both.
To connect using basic authentication – I presume you have a plan to enable MFA soon, as you should – follow this process:
1. Open Powershell as an admin and run this command:
This command configured Powershell to be allowed to run downloaded scripts from trusted publishers, which is necessary for this process.
2. We first need Powershell to collect your username and password. Enter this command:
$UserCredential = Get-Credential
…Then enter your 365 username and password into the dialogue box and hit OK.
3. Next, we need to connect to an Exchange Online Poweshell session using those credentials:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
4. We need to import the session in order to actually use it. Run this command:
Import-PSSession $Session -DisableNameChecking
…and done! You’re now connected to your Exchange Online Powershell session via basic authentication.
But of course, we don’t to be using basic authentication in 365 – which will eventually be phased out anyway. For those of you who have already followed my Conditional Access MFA guide, we need to connect you through the Powershell MFA process.
If this is the first time you’ve done this on your local PC, you’ll need to take a few steps first to prep your environment. If you know you completed those preparatory steps before, then you can skip to step 4.
1. You need to download and install the official Exchange Online Powershell V2 module. Firstly, we need to ensure you have the newest version of PowershellGet. Microsoft has a good, short KB on that process.
2. Run the script execution allowance policy:
3. Close and reopen Powershell as admin in order to commit all changes, then run the module install command:
Install-Module -Name ExchangeOnlineManagement
4. Now let’s begin the real connection process. In Powershell, enter the following command:
Connect-ExchangeOnline -UserPrincipalName <UPN> -ShowProgress $true
…and substitue your username where is says <UPN> – for example, firstname.lastname@example.org.
5. If your 365 credentials are already cached, then you may not even be prompted to enter anything or go through MFA – otherwise, you’ll be given the typical 365 login prompt with MFA provided.
…and, done! You’ve now connected to the Exchange Online V2 session using MFA.