How to Remote PowerShell into Exchange Online using Prefix

1

image

In my last blog I wrote about how to connect to Exchange Online using a remote PowerShell session.

But if your are running your on-premise Exchange 2010 and connecting to Exchange Online at the same time, it would be nice to be able to distinguish between the commands you run in PowerShell against the on-premise or the online Exchange.

This can be done using a prefix setting, when you import your Exchange Online session.

See my last blog post for the details about connecting to Exchange Online: How to Remote PowerShell into Exchange Online (Office 365).

Here’s a quick walk though the initial steps needed, before we get to the part, that is different from my last blog post about the subject. For more details, see my last blog post.

Run the following commands:

To connect to Exchange Online, just start a PowerShell session and type in following commands:

$Cred = Get-Credential

 

The above command prompts you, for your Office 365 tenant admin credentials, it is important to enter as UPN format, such as e.g. admin@contoso.onmicrosoft.com.

Next, we will create a new remote PowerShell session using the following cmdlet:

$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $cred -Authentication Basic –AllowRedirection

 

The part below is new from my last blog post and where we add the prefix to our command, during the import of the PowerShell session:

Import-PSSession $s –prefix o365

 

You are now connected to Exchange Online with you Office 365 Tenant admin and can use Exchange Online PowerShell cmdlets available.

SNAGHTML45f97c
Now when you run Exchange commands in PowerShell, you have to remember to prefix them with o365, otherwise you run commands against your on-premise Exchange (if connected from where you run this).

An example could be getting a list of mailboxes as the above screenshot, the command would be:

Get-o365mailboxes

 

For information about Exchange Online PowerShell cmdlets available see Reference to Available PowerShell Cmdlets in Exchange Online.

To remove the PowerShell session again, run the following command:

Remove-PSSession $s

About Author

Peter is an Exchange specialist with over 15+ years of experience with Exchange Server and certified Microsoft Certified Master (MCM) and Microsoft Certified Solutions Master (MCSM) on Exchange Server. He has been awarded the Microsoft MVP award, every year since 2007. He is active in the Microsoft community and User Group Leader for CoLabora (a danish UC & Cloud User Group). He works as an Cloud & Infrastructure Architect and Consulent, with primary focus on Exchange, Office 365, Azure and Skype for Business.

1 Comment

  1. Pingback: msdigest.net » How to Remote PowerShell into Exchange Online using Prefix « JC’s Blog-O-Gibberish

Leave A Reply

Copyright 2005-2015 - Peter Schmidt.