Add a Prefix to Differentiate On-Prem from Cloud Exchange Cmdlets

If you use PowerShell to manage both on-prem and cloud Exchange resources, you can manage both in the same console by adding a prefix to the cmdlets of one or the other. It’s easier to add the prefix for Exchange Online cmdlets, so I’ll show you that.

Simply copy and paste this code into the on-prem Exchange Management Shell to connect to Exchange Online and prefix the noun portion of all online cmdlets with “Cloud”. The verb portion of the cmdlets doesn’t change, so Get-Mailbox becomes Get-CloudMailbox, and Get-AcceptedDomains becomes Get-CloudAcceptedDomains.

$Cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange `
     -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
     -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $Session -Prefix Cloud

Here’s how it looks in the shell:

Adding a prefix to session cmdlets in PowerShell

The first Get-MailContact queries the local Exchange installation for a contact with alias, “george.burns”. The second Get-CloudMailContact queries Exchange Online for a mail contact with the same alias.

Leave a Reply

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