Connect PowerShell to Exchange Online (Office 365)

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):

  1. Run Windows Power Shell as Administrator
  2. 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
  3. Run: Connect-ExchangeOnline
  4. Log in with your Office 365 admin credentials.
    Microsoft Authentication
  5. To test a successful connection, run: Get-Mailbox
  6. To disconnect, run: Disconnect-ExchangeOnline

==============================================================================
====================== Old Method (Basic Authentication, no MFA) ======================
==============================================================================

Windows PowerShell

Following instructions will help to connect Windows PowerShell to your Microsoft Exchange Online or Office 365 service.

  1. Run Windows Power Shell as Administrator
  2. Run Set-ExecutionPolicy Unrestricted
  3. Run $LiveCred = Get-Credential
  4. Provide your Office 365 administrator account credentials
  5. Run $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
  6. 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

 


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha
captcha
Reload