Select Page

As part of my job I’m working a lot with Office 365, and in particular Exchange Online. I’m using the following code to connect to Exchange Online. Feel free to give me suggestions to improve it.

The Code:


  • Line 1: Checks for existence of the $cred variable. If it doesn’t exists, the cmdlet Get-Credential is executed and you will be asked for the Exchange Online credentials. Be sure to use credentials that has permissions to actually do something in Exchange Online.
  • Line 2: Checks if there is already a PowerShell Remoting session with configuration name Microsoft.Exchange. It can be that you already have a connection established. This makes sure that you don’t have clobber in your current PowerShell console.

The use of the code is simple. Just paste it into PowerShell console and execute it:

The code given in this article was developed and tested on:

  • Windows 10 Enterprise Build 10.0.15031.0
  • PowerShell Version 5.1.15031.0
  • PowerShell Edition Desktop
  • BuildVersion 10.0.15031.0
  • PSRemotingProtocolVersion 2.3