Time to check your PoSH-connection to Exchange Online

I’ve been using the same action to connect my Powershell-session to Office 365 and Exchange Online for quite some time now. A while ago, I created a function that lives in my ‘all users, all hosts’ Powershell-profile to setup the remoting session to Exchange Online:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
function Open-MSOLConnection
{
  <#
    .SYNOPSIS
    Connects and loads a MSOL PoSH Connection.
    .DESCRIPTION
    Gets credential for MSOL Session, configures a new session and loads it.
    .EXAMPLE
    Open-MSOLConnection
    #>
  $LiveCred = Get-Credential
  $Session = New-PSSession -Name MSOL -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $LiveCred -Authentication Basic -AllowRedirection
  Import-PSSession $Session
  connect-msolservice -credential $LiveCred
}

As you can see, the function gets the credentials for setting up the session and creates the remoting session to the Exchange Online endpoint.

It turns out I’ve been using the https://ps.outlook.com/powershell endpoint all the time, while the endpoint has changed. So far, this hasn’t been a problem but recently it started acting up. This seems related to the 10525 Windows 10 release, but that could be a coincident. The endpoint should be https://outlook.office365.com/PowerShell-liveId

So I changed the function in my profile:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
function Open-MSOLConnection
{
  <#
    .SYNOPSIS
    Connects and loads a MSOL PoSH Connection.
    .DESCRIPTION
    Gets credential for MSOL Session, configures a new session and loads it.
    .EXAMPLE
    Open-MSOLConnection
    #>
  $LiveCred = Get-Credential
  $Session = New-PSSession -Name MSOL -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/PowerShell-liveId -Credential $LiveCred -Authentication Basic -AllowRedirection
  Import-PSSession $Session
  connect-msolservice -credential $LiveCred
}

After this, everything worked like a charm again 🙂

Lessons learned
When using custom functions to perform regular tasks, be sure to check stuff like this every once in a while to stay up to date with changes in the services.

If you want to connect to all O365 services in one Powershell windows, including SharePoint, Skype for Business and the compliance center, there is a pretty decent write-up on TechNet that you can use a starting point.