Connect Exchange Online using 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
}

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.

Riaz Javed Butt

Riaz is a technology evangelist with over 8 years of extensive experience with expertise on Identity Management, Exchange Server, Office 365 and a bit of System Center. Riaz is currently working as Lead Consultant. His technical experience is followed by 8 years consulting positions advising both internal and external (local & International) stakeholders/customers on strategic technology selection and adoption along with delivery of solutions across a range of business units. He is a regional lead speaker for Microsoft Office 365 and also speaks in community forums.

This Post Has One Comment

  1. Imran Rafique

    Very helpful Post , works for me 🙂

Leave a Reply