Connect to Exchange Online using PowerShell 5/5 (3) 2 min read

To be able to create a remote PowerShell session to Exchange Online, we can use the “Windows built PowerShell console”.

We will need to use some “first-time” configurations, and then, the rest of the process includes running the required PowerShell command for connecting to Exchange Online.

PowerShell console – First-time configuration

To be able to find the built-in PowerShell console, use the search option in the start menu by looking for the word PowerShell.

In the search results, we can see the required PowerShell console named – Windows PowerShell

Connect to Exchange Online using remote PowerShell -01

To be able to run the required PowerShell commands, we will need to activate the Windows PowerShell console using the option of – Run as administrator

Right click on the Windows PowerShell icon and choose the menu – Run as administrator

Connect to Exchange Online using remote PowerShell -02

We will need a PowerShell command that will provide the required permission for running PowerShell command

Set-ExecutionPolicy Unrestricted –force

In the following screenshot, we can see an example. To execute the PowerShell command, press the ENTER key

Connect to Exchange Online using remote PowerShell -03

Running the PowerShell set of command for connecting Exchange Online

The connection to Exchange Online by using remote PowerShell is implemented by using three sets of PowerShell command.

$UserCredential = Get-Credential

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

Import-PSSession $Session

Technically, we can copy this set of command and paste it in the Windows PowerShell console.

When we use the option of “copy and paste” for paste a “long set” of PowerShell command, we can experience some problem which relates to issues such as – spaces etc.

If you experience such problems, try to paste the PowerShell command by copy and paste each one of the PowerShell command set.

Step 1#3 – using the credentials PowerShell command

Copy and paste the following PowerShell command

$UserCredential = Get-Credential

Connect to Exchange Online using remote PowerShell -04

As a result, an authentication window will appear

Type in your Office 365 global administrator credentials.

Connect to Exchange Online using remote PowerShell -05

Step 2#3 – connecting to Exchange Online

The following PowerShell command serves for specifying the Exchange Online URL address that is used for the remote PowerShell session

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

Connect to Exchange Online using remote PowerShell -06

Step 3#3 – Import Exchange Online PowerShell cmdlets

This is the last phase; which we import all of the Exchange Online cmdlets to the existing PowerShell console.

Copy and paste the following PowerShell command

Import-PSSession $Session

In the following screenshot, we can see the result.

Connect to Exchange Online using remote PowerShell -08

Verifying that the remote PowerShell connection was successfully completed

In case that you want to verify the remote PowerShell session to Exchange Online was successfully completed, you can try to run basic PowerShell cmdlets such as

Get-Mailbox

In the following screenshot, we can see the result of the Get-Mailbox command.

Connect to Exchange Online using remote PowerShell -09

PowerShell command syntax – Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article


Summary
Connect to Exchange Online using PowerShell
Article Name
Connect to Exchange Online using PowerShell
Description
To be able to create a remote PowerShell session to Exchange Online, we can use the “windows built PowerShell console”.We will need to use some “first-time” configurations and then, the rest of the process includes running the required PowerShell command for connecting to Exchange Online.
Author
Publisher Name
o365info.com
Publisher Logo

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

Leave a Reply

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