What’s Prefix switch in Import-PsSession and how to use it?

Microsoft recently mentioned something about Prefix switch for Import-PSSession command. It is very useful when you are working in hybrid Exchange environment and wants to collect informaiton from both On-Prem Exchange and Exchange Online.

Let’s say you want some complete list of mailboxes using one script i.e. list of both On-Prem and Cloud mailboxes. In this case we can simply pull this information by using -Prefix switch on session import:

Open on-premises Exchange Powershell session and Connect to the Exchange Online PS-


Notice the -Prefix O365 in the last line. It will add O365 as Prefix in all Exchange Online Commands. For instance, if you want to pull information of Exchange Online Mailbox then you can simply write it as Get-O365Mailbox:


You just need to combine above two lines and it will look something like this:


After this $mbxs will have complete list of mailboxes for both on-premises and in the Cloud. You can use this sample code for your script and adjust it accordingly.

Leave a Reply

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