Connect Exchange Online using PowerShell

Published: Updated: 1 min readMicrosoft 365 Admin, PowerShell

Managing Exchange online with PowerShell requires you to connect with Exchange Online. Few months ago i was working on automating the process of connecting with Exchange online rather then writing the cmdlets every time i connect with Exchange online and you know what i come up with ? Powershell Function which makes it so easy for me to connect to Exchange Online anytime i want to and i don’t have to write cmdlets every time. The function is as below.

# PowerShell Function to connect with Exchange Online

Function Connect-ExchOnline {
$ExchOnlineCred = Get-Credential

Write-Output “You are Connecting to Exchange Online. After successful authentication PowerShell will load Exchange Online Cmdlets”

#Create remote Powershell session with Exchange Online
$ExchOnlineSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/PowerShell -Credential $ExchOnlineCred -Authentication Basic -AllowRedirection

#Import the remote PowerShell session

Import-PSSession $ExchOnlineSession -AllowClobber | Out-Null
}

Connect Exchange Online using PowerShell - screenshot

2

3

You can download this PowerShell function script from Technet Gallery. This script is basically a function and I didn’t “call” the function in the script self. Try dot-sourcing the script first and then running it using Connect-ExchOnline and enter your Office 365 admin credentials to connect.

Share:
Riaz Javed Butt

Riaz Javed Butt

Riaz Javed Butt is a Microsoft consultant specialising in Exchange Server, Office 365 and identity management, and a community speaker on Microsoft 365.

More posts by Riaz Javed Butt

One response to “Connect Exchange Online using PowerShell”

  1. Imran Rafique Avatar
    Imran Rafique

    Very helpful Post , works for me 🙂

Leave a Reply

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