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
To connect in other Office 365 offerings, use the following settings:
- Office 365 operated by 21Vianet: -ConnectionURI https://partner.outlook.cn/PowerShell-LiveID
- Office 365 Germany: -ConnectionURI https://outlook.office.de/PowerShell-LiveID -AzureADAuthorizationEndpointUri
- 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
Connect-EXOPSSession [[-ConnectionUri] <String>] [[-AzureADAuthorizationEndpointUri] <String>] [[-PSSessionOption]
<PSSessionOption>] [-BypassMailboxAnchoring] [<CommonParameters>]
This PowerShell module allows you to connect to Exchange Online service
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:
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!