Connect to Office 365 Exchange PowerShell

KB ID 0001410


If there’s one thing thats grown on me it’s PowerShell, After the last few versions of Exchange you can’t really escape it. So now we have so many clients with their Exchange in Office 365. The ability to connect to that, and use all your usual Exchange commandlets is a bonus!

WARNING: This process may end up with you getting an “Access is denied” error, if you are using modern authenticiction, or MFA. If so use this article instead.


If you haven’t already done so, you need to ‘slacken‘ your signing policy, (a little) before proceeding;

Set-ExecutionPolicy RemoteSigned

Now to access Exchange online you need to be able to authenticate to it, the best way to do that is to ‘cache’ your logon credentials. (Unless you have ADFS Federation then you can skip this step). To enter your O365 creds execute the following command;

$UserCredential = Get-Credential

Then create the settings for your remote session;

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

Then to open the session;

Import-PSSession $Session

PowerShell into Office 365 Exchange

DON’T FORGET: When you are finished, to disconnect the session with the following command;

Remove-PSSession $Session

Related Articles, References, Credits, or External Links


Author: PeteLong

Share This Post On

Submit a Comment

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