This article explains how to connect to Exchange Online with PowerShell.
You need to be a Global Administrator in the Office 365 Tenant, or at the least be assigned to the Exchange Administrator role.
You need to be using a 64-bit version of one of the following Windows OS:
- Windows 10
- Windows 8 or 8.1
- Windows 7 SP1
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2 SP1
You need to install Microsoft .NET Framework 4.5.x, and either Windows Management Framework 3.0 or 4.0.
The following modules are required:
- Microsoft Online Service Sign-In Assistant for IT Professionals RTW
- Windows Azure Active Directory Module for Windows PowerShell (64-bit)
Configure PowerShell to run signed scripts for Exchange Online. Run the following in an elevated PowerShell session:
Connect to Exchange Online
Create a PowerShell credentials object:
$credential = Get-Credential
A dialog box will appear to enter your credentials. Enter your username and password, then click OK.
Run the following command:
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid -Credential $credential -Authentication “Basic” -AllowRedirection
Although a connection has been established to Office 365, it’s necessary to run the following command to download scripts, cmdlets, etc. to manage Exchange Online:
Import-PSSession $exchangeSession -DisableNameChecking
Close the Connection
When you’re done, closing the PowerShell window will leave the remote connection to Exchange Online active for the next 15 minutes. It’s good practice to end the session when you’re done.