How to set up a quick connection to Exchange Online via PowerShell

How to set up a quick connection to Exchange Online

If you’re going to be working with Office 365 via PowerShell, it’s a good idea to set up your computer with the appropriate PowerShell cmdlets and versions.

It’s also a good idea to create shortcuts to the various Office 365 services, so you can quickly log on to them without having to copy and paste commands one by one.

Here are some instructions on TechNet that detail the prerequisites for a connection to Exchange Online, though you might find you’ve got these installed already: https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx

Easily connect to Exchange Online via PowerShell

Open PowerShell as an administrator

Go to Start, search for PowerShell, right click Windows Powershell and Run as Administrator
Open PowerShell As An Administrator To Connect To Exchange Online

Create a PowerShell profile with a function

Run this:

New-item –type file –force $profile

Create A New PowerShell Profile

Then this:

notepad $profile

Open PowerShell Profile In Notepad

Now copy the following PowerShell function into the notepad document and save it:

(Be sure to replace [email protected] with your username).

Function Connect-EXOnline{

$credentials = Get-Credential -Credential [email protected]
Write-Output "Getting the Exchange Online cmdlets"

$Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-ConfigurationName Microsoft.Exchange -Credential $credentials `
-Authentication Basic -AllowRedirection
Import-PSSession $Session


Save Exchange Online Function In Notepad

Use the new function to connect quickly to Exchange Online

Close Powershell and run it again.

From now on you can just type Connect-ExOnline, or just type connect and press TAB.

Run Function To Connect To Exchange Online

Enter your password and you’re good to go.

Get The Exchange Online Cmdlets

Now your computer is set up to connect to Exchange Online without having to copy and paste multiple commands.

Connection To Exchange Online Via PowerShell Is Successful

Was this article helpful?

Related Articles

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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