The MS365 Cloud provides many web interfaces to manage the different services it offers. But like any graphical interface, not everything is available. For some advanced settings, you need to use APIs or use Powershell command line administration.
This article shows you how to connect to Exchange Online from the Powershell command line.
2. The different versions of Exchange Online modules
There are two versions of PowerShell modules available for Exchange Online:
- Exchange Version 1.0 module based on Remote Power Shell
- Exchange Version 2.0 module based on REST API access (and Remote Power Shell for some commands)
Note: These two versions support login with oAuth authentication and MFA. This point is important because basic authentication will not be supported soon.
3. Using PowerShell Exchange Onlive V1
It is easy to access the Exchange Online module using the following URL and Edge browser:
This link allows you to download a program that will open a PowerShell window with the possibility of connecting to Exchange Online using the “connect-exopssession” command.
You can specify your administrator account with the -userprincipalname option or specify it when requesting accounyt and password. If the MFA is active on your administrator account, you will be asked for it.
Once connected, you will have hundreds of Exchange Online PowerShell commands available.
It is also possible to retrieve this module once it is installed on your computer in the %userprofile%\AppData\Local\Apps\2.0 folder.
The “Microsoft.Online.CSE.PSModule.Client.exe” program allows you to directly launch a PowerShell window with the Exchange Online V1 module.
You can directly download this module with its executable program from our site: https://admin365.fr/download/2020-05_Admin_Exchange_Online_V1.zip
Note: For this Exchange Online V1 module to work, your computer must allow basic WinRM authentication even if you connect in oAuth. If the HKLM\Software\Policies\Microsoft\Windows\WinRM\Client\AllowBasic registry key is set to 0 on your computer, it will be impossible to connect to Exchange Online with this module.
4. Using PowerShell Exchange Onlive V2
The Exchange Onlive V2 module is the new version of the Exchange Online module. This version allows each update to have more commands available directly in REST API and no longer in Remote Power Shell. REST API commands offer better performance and natively support oAuth type authentication.
You can download this module using the following link: https://www.powershellgallery.com/packages?q=ExchangeOnlineManagement
You can install the module with the command “install-module -ExchangeOnlineManagement” or download the NUPKG file that you simply have to rename in .ZIP to access the module.
If you have opted for manual installation, you have just to copy the content of the .ZIP file (ExchangeOnlineManagement folder) into one of your Powershell module folders available using the “$env:psmodulepath” variable.
Note: If you are not the administrator of your workstation, you can always copy the Exchange Onlive V2 module into the “Modules” folder of your Windows profile. Then remember to unlock the .DLL and .PSM1 files so that you can launch the module with a simple user account.
Once the module has been copied into one of the PowerShell module folders, you can import it into a PowerShell window with the “import-module exchangeonlinemanagement” command.
To connect to Exchange Online, you will need to use the “connect-exchangeonline” command.
Version 2.0.6 of the Exchange Online V2 module includes approximately 250 commands in REST API, for the other commands that do not yet exist in REST API, you must use Remote Power Shell access. If you need these commands you must add the -UseRPSSession option when you connect PowerShell to Exchange Online.
If you use this -UseRPSSession option, your computer must allow basic authentication even if you connect in oAuth.
If the HKLM\Software\Policies\Microsoft\Windows\WinRM\Client\AllowBasic registry key is set to 0 on your computer, it will be impossible to use the module commands that are not in REST API.