Since rollout in Exchange 2007, PowerShell and Exchange have been partners in helping administrators everywhere manage their environments. Whether on-premises or in the cloud, PowerShell is a powerful tool for working with Exchange. Now the cmdlets for managing Exchange Online are available in Azure Cloud Shell.

In this post, I'll show you how to access the Exchange Online module easily, and begin working with your Exchange Online resources in Azure Cloud Shell.

Connecting to Exchange Online

To start, we need to establish a connection to Exchange Online in Azure Cloud Shell with the Connect-EXOPSSession cmdlet. This cmdlet connects to Exchange Online with managed identity for Azure (MSI) using your current login.

Before actually connecting to Exchange Online, let's take a look at what this cmdlet has to offer using get-help .

PS Azure:\> get - help Connect-EXOPSSession NAME Connect-EXOPSSession SYNOPSIS To connect in other Office 365 offerings, use the following setting s: - Office 365 operated by 21 Viane t: -ConnectionURI http s: //partner.outlook. cn /PowerShell-LiveID -AzureADAuthorizationEndpointUri http s: //login.chinacloudapi. cn /common - Office 365 Germany: -ConnectionURI http s: //outlook.office.de/PowerShell-LiveID -AzureADAuthorizationEndpointUri http s: //login.microsoftonline.de/common - This PowerShell module allows you to connect to Exchange Online service. - To connect to the Exchange Online Service use "Connect-EXOPSSession" cmdlet - Uses MSI to login as yourself, and Device login to other tenant as syndicated partner - EnableEXOTelemetry To collect telemetry on Exchange cmdlets. Default value is False. - DoLogErrorMessage Switch to enable/disable error message logging in telemetry file . Default value is True. - PSSessionOption accept object created using New-PSSessionOption SYNTAX Connect-EXOPSSession [[-ConnectionUri] <String> ] [[-AzureADAuthorizationEndpointUri] <String> ] [[-PSSessionOption] <PSSessionOption> ] [-BypassMailboxAnchoring] [ <CommonParameters> ] DESCRIPTION This PowerShell module allows you to connect to Exchange Online service RELATED LINKS http s: // go .microsoft. com /fwlink/ p /?linkid= 837645 REMARKS To see the examples, type : "get-help Connect-EXOPSSession -examples" . For more information, type : "get-help Connect-EXOPSSession -detailed" . For technical information, type : "get-help Connect-EXOPSSession -full" . For online help , type : "get-help Connect-EXOPSSession -online"

So we see that we have a few optional parameters that can be used. Generally, you'll simply run the command as is since you are already logged into Azure through Cloud Shell, and MSI will take care of the authentication for you.

To connect to Exchange Online, simply enter the following:

PS Azure: \> Connect-EXOPSSession

This process takes a few moments as the connection is made, and the Exchange Online cmdlets are temporarily loaded into the shell as shortcut to the actual cmdlets being run inside of Exchange Online. The process uses implicit remoting, a technique for accessing a PowerShell module from a remote system without permanently installing the module based on Import-PSSession . For more information on implicit remoting and Import-PSSession , see this doc.

Finding the Exchange Commands

Normally, cmdlets available within PowerShell in Cloud Shell would be part of an installed and loaded module. However, when you search the modules in Cloud Shell, you won't find any modules explicitly calling out Exchange. That is because implicit remoting creates a temporary module containing the imported cmdlets shortcuts to the actual cmdlets running in Exchange Online. So you are not actually running the commands in your shell, but on the remote system's shell environment. It's easy to find as it will be the only module name starting with tmp_ as seen in the listing below:

PS Azure:\> get-module ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 1.5 .2 Az.Accounts { Add -AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccou… Script 2.0 .0 Az. Compute { Add -AzContainerServiceAgentPoolProfile, Add -AzImageDataDisk, Add -AzV… Script 1.8 .0 Az.Network { Add -AzApplicationGatewayAuthenticationCertificate, Add -AzApplication… Script 1.3 .1 Az.Resources { Add -AzADGroupMember, Export -AzResourceGroup, Get-AzADAppCredential, … Script 1.3 .0 Az.Storage { Add -AzRmStorageContainerLegalHold, Add -AzStorageAccountManagementPol… Script 0.0 .0 .9 AzureAD.Standard.Preview { Add -AzureADAdministrativeUnitMember, Add -AzureADApplicationOwner, Ad… Script 0.9 .3 AzurePSDrive Script 17.0 .2985 … EXOPSSessionConnector Connect-EXOPSSession Manifest 6.1 .0 .0 Microsoft.PowerShell.Management { Add -Content, Clear-Content, Clear-Item, Clear-ItemProperty…} Manifest 6.1 .0 .0 Microsoft.PowerShell.Utility { Add -Member, Add - Type , Clear- Variable , Compare-Object…} Script 0.9 .3 PSCloudShellUtility {Disable-AzVMPSRemoting, Dismount-CloudDrive, Enable-AzVMPSRemoting, … Script 2.0 .0 PSReadLine {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove -PSReadLineKey… Binary 0.8 .1 SHiPS Script 1.0 tmp_fc3yzdtj.qan { Add -MailboxFolderPermission, Approve-ElevatedAccessRequest, Clear-Ac…

Notice under exported commands, the first command is Add-MailboxFolderPermission so we know that is the module we want to work with.

Now to see the commands available within the module, we use get-module and select out the commands as seen here:

PS Azure:\> get-module tmp* | Select -ExpandProperty ExportedCommands Key Value --- ----- Add-MailboxFolderPermission Add-MailboxFolderPermission Approve-ElevatedAccessRequest Approve-ElevatedAccessRequest Clear -ActiveSyncDevice Clear -ActiveSyncDevice Clear -MobileDevice Clear -MobileDevice Clear -TextMessagingAccount Clear -TextMessagingAccount Compare-TextMessagingVerificationCode Compare-TextMessagingVerificationCode Deny-ElevatedAccessRequest Deny-ElevatedAccessRequest Disable -App Disable -App Disable -InboxRule Disable -InboxRule Disable -SweepRule Disable -SweepRule Disable -UMCallAnsweringRule Disable -UMCallAnsweringRule Enable -App Enable -App Enable -InboxRule Enable -InboxRule Enable -SweepRule Enable -SweepRule Enable -UMCallAnsweringRule Enable -UMCallAnsweringRule Get-ActiveSyncDevice Get-ActiveSyncDevice Get-ActiveSyncDeviceStatistics Get-ActiveSyncDeviceStatistics ...

You'll note I used tmp* for the module name since there is only one temporary module. You would need to call the full name should you have other temporary modules in your session.

Now you have access to the Exchange Online cmdlets. At the time of this blog, that is 131 cmdlets available in Cloud Shell. This may change over time as more cmdlets and other services are added.

Working with Exchange Online Cmdlets

Once connected, you can begin using the cmdlets as you normally would. For example, you can view the non-exchange information for a user object in your Exchange organization using get-user .

View user objects in Azure Cloud Shell using Get-User

Looking for mailbox-specific information? Try get-mailbox .

Lising a mailbox in Azure Cloud Shell using Get-Mailbox

And like all commands in PowerShell, you can use the pipeline and filtering techniques to find more specific information.

Note: Because these cmdlets are temporary using implicit remoting, the help files are not available within the shell. So if you need to see the help file for a command, you'll need to use a local install of the Exchange PowerShell tools or you can view the Exchange PowerShell cmdlets at docs.microsoft.com

Was this post helpful? Do you have other Questions/Comments? Let me know in the comments below!

Would you like to see other Office 365 services available in Cloud Shell? Then add your vote to User Voice to 'allow all 365 management shell access via cloudshell'

If you want more information on commands from this blog, check out the docs below:

Connect to Exchange Online with PowerShell

Import-PSSession

Managed identities for Azure (MSI)

Exchange PowerShell Reference

Get-User

Get-Mailbox

Connecting to Exchange Online using Connect-EXOPSSession