To connect to Office 365 Exchange Management Shell, use the following method (this uses modern authentication and works with or without Multi Factor Authentication – MFA):
- Run Windows Power Shell as Administrator
- This step only needs to be done once on each PC you are connecting from:
- Run: Install-Module -Name ExchangeOnlineManagement -RequiredVersion 2.0.5
For an updated command and new versions check PowerShell Gallery. - Run: Import-Module ExchangeOnlineManagement
- Run: Install-Module -Name ExchangeOnlineManagement -RequiredVersion 2.0.5
- Run: Connect-ExchangeOnline
- Log in with your Office 365 admin credentials.
- To test a successful connection, run: Get-Mailbox
- To disconnect, run: Disconnect-ExchangeOnline
==============================================================================
====================== Old Method (Basic Authentication, no MFA) ======================
==============================================================================
Following instructions will help to connect Windows PowerShell to your Microsoft Exchange Online or Office 365 service.
- Run Windows Power Shell as Administrator
- Run Set-ExecutionPolicy Unrestricted
- Run $LiveCred = Get-Credential
- Provide your Office 365 administrator account credentials
- Run $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
- Run Import-PSSession $Session
You should now be connected to your Office 365 account. To test connection you can run Get-Mailbox which should list all mailboxes in your Hosted Exchange account.
To disconnect from the service run: Remove-PSSession $Session
Leave a Reply