Quantcast
Channel: o365info
Viewing all articles
Browse latest Browse all 373

Connect to Exchange Online using PowerShell

$
0
0

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 on 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 relate to problems 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!
We really want to know what you think about the article

The post Connect to Exchange Online using PowerShell appeared first on o365info.com.


Viewing all articles
Browse latest Browse all 373

Trending Articles