1. Home
  2. Office 365
  3. How to Connect to Exchange Online via PowerShell
  1. Home
  2. PowerShell
  3. How to Connect to Exchange Online via PowerShell

How to Connect to Exchange Online via PowerShell

Below is a walkthrough showing you how to connect to Office 365 Exchange Online via PowerShell

  • Click on the start menu and open PowerShell
  • Enter the following command. This is used to save your office 365 credentials into PowerShell
  • $UserCredential = Get-Credential

Note: If you get the following error it means PowerShell has not been configured to run scripts

“Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files.”

The following link will run you through configuring PowerShell to run scripts
http://itwalkthroughs.com/knowledge-base/configure-powershell-to-run-scripts/

  • When the Windows PowerShell Credential Request¬†opens enter the username/password for a Global Admin account and click¬†Ok
  • Run the following command to connect to your Exchange Online instance
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
  • Run the following command to import the required cmdlets
  • Import-PSSession $Session

If you don’t receive any errors you are now connected to Exchange Online.

If you would like to test the connection run Get-Mailbox cmdlet which will show you a list of all Office 365 mailboxes.

Updated on March 28, 2019

Was this article helpful?

Related Articles

Leave a Comment