Good evening

Some PowerShell Commands are available online and on-premise, for example, Get-MailContact

Is there a way to recognize if the local Server or e.g. Exchange online is answering the call of this kind of command?

I would have expected to be able to ask the PSSession what commands it responds to, but that seems to be a red herring.

Thanks a lot for any help! Kind regards, Thomas

0

2 Answers

Use prefixes when using imported cmldets.

Import-PSSession

Import-PSSession [-Prefix ] [-DisableNameChecking] [[-CommandName] <String[]>] [-AllowClobber] [-ArgumentList <Object[]>] [-CommandType ] [-Module <String[]>] [-FullyQualifiedModule <ModuleSpecification[]>] [[-FormatTypeName] <String[]>] [-Certificate ] [-Session] []

You can use any prefix you choose.

Example(s):

Import-PSSession -Session $ExchangeOnPremSession -Prefix 'EXP' Import-PSSession -Session $ExchangeOnlineSession -Prefix 'EXO' Import-PSSession -Session $SkypeOnlineSession -Prefix 'SOL' Import-PSSession -Session $SqlSession -Prefix 'SQL' Import-PSSession -Session $WapSession -Prefix 'WAP' 

This way, when using Exchange Online your cmdlets would be shows as Get-ExoMail and on-premises would be the normal Get-Mail cmdlet. Or you can explicitly use say EXO for online, and EXP for on-premises.

So, the use case would be:

Get-ExoMailbox 

Or

Get-ExpMailbox 

... all else about the cmdlet is the same.

This prefix thing is not new, you can do this for your custom stuff (variables, functions, etc) as well, for easy discovery, use, and disposal.

***Note:

The new Exchange Online already does this, in the new modules, so, no need for the prefix.***

Get-EXOMailbox

Module: ExchangePowerShell

Applies to: Exchange Online

This cmdlet is available only in the Exchange Online PowerShell V2 module. For more information, see About the Exchange Online PowerShell V2 module.

You could run the following command to view which module the command is using:

(Get-Command -Name <Cmdlet>).ModuleName

  1. If it's an Exchange Online command(Basic):

enter image description here

  1. If it's an Exchange Online command(V2):

enter image description here

  1. If it's an on-prem Exchange command, there will a server fqdn output in PowerShell:

enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy