Office 365 PowerShell – Part 3

In the previous article, we took a look at how we can use PowerShell to connect to Skype for Business Online. In this article, we will continue with connecting and managing other services in the Microsoft cloud. Namely, we will be talking about Exchange Online.

Exchange Online

To connect to Exchange Online, no additional software is needed. All that we need to do is open up our favourite scripting tool and run a few commands in order to connect/import a session, similar to Skype for Business.

$Exchange=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "" -Credential $MyAccount -Authentication "Basic" -AllowRedirection
#Import Session
Import-PSSession $Exchange

After successfully running these commands, we can use the window to see which commands were imported into our session.

In the picture above, we can see that after running:

Import-PSSession $Exchange

A temporary module with a random name is imported into our PowerShell window. In our case, it is »tmp_j34mn4zb.abt«. This piece of information can be very important, if we would like to, for example, list all commands that this module contains:

Get-Command -Module tmp_j34mn4zb.abt

At the moment, 669 commands are available for Exchange Online.

End of Session

Similar to Skype for Business, it is also important to end our session when we complete our work on Exchange Online and cut the connection to Office 365. To finish our session, we must use the following command:

Remove-PSSession $Exchange

This command also deletes the temporary module that we opened with the “Import Session” command, which means that Exchange Online cmdlets won’t be available anymore.

Exchange Online and Multifactor Authentication

In case your organisation uses Multifactor Authentication (MFA), you will need to take a different approach in order to connect to Exchange Online. You will need to open and open the Exchange administration page:

A link called “Hybrid” will be available on the bottom of the navigation on the right side. If you open the site for configuring the hybrid environment, you will find 2 links:

The place where the option to start the MFA module is situated may be a bit strange, but unfortunately there is no other option at the moment. If you wish to start the module for connecting, click the “Configure” button. An application that will open a new PowerShell window will run. Use it to run the following command:


After logging in successfully, you can use PowerShell to manage your Exchange Online, even though you have MFA set up.

That’s all for this article. In the next one, we will take a look at SharePoint Online administration.

Robi Vončina

Author: Robi Vončina

Office Servers and Services MVP, MCT

Leave a Reply

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