Connect to Exchange Online using Remote PowerShell

As an administrator for Office 365, you will be required to use PowerShell for various tasks on Exchange Online. While SharePoint Online and Azure Active Directory has their own PowerShell module to download, You use Windows PowerShell on your local computer to create a remote PowerShell session to Exchange Online. It’s a simple three-step process where you enter your Office 365 credentials, provide the required connection settings, and then import the Exchange Online cmdlets into your local Windows PowerShell session so that you can use them.

I would assume you have one of the following version of Windows and have installed Microsoft.NET Framework 4.5 or later and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0.

  • Windows 10
  • Windows 8 or Windows 8.1
  • Windows Server 2012 or Windows Server 2012 R2
  • Windows 7 Service Pack 1 (SP1)*
  • Windows Server 2008 R2 SP1*

To enable Windows PowerShell to run signed scripts, run the following command in an elevated Windows PowerShell window (a Windows PowerShell window you open by selecting Run as administrator):

Set-ExecutionPolicy RemoteSigned

This is a one time thing for a given environment and you don’t have to run it every time you use PowerShell for Exchange Online. Now let’s connect to Exchange Online using the following steps.

On your local computer, open Windows PowerShell and run the following command.

$UserCredential = Get-Credential

In the Windows PowerShell Credential Request dialog box, type your Office 365 user name and password, and then click OK.

Run the following command

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Run the following command

Import-PSSession $Session

And voila, you are ready to use PowerShell for your Exchange Online environment. Once you are done with your activity, its always a good practice to disconnect the session. Run the following command to disconnect the session.

Remove-PSSession $Session

If your account is not configured for remote PowerShell access, you can follow the steps in this article to configure it.