slider-img

Connect to Exchange Online (O365) Using Remote PowerShell

Remote PowerShell allows you to manage your existing Exchange Online (O365) settings from a command line using Windows PowerShell installed on your local computer. This will allow you to create a remote Shell session to your Exchange Online account–same as using Exchange Management Shell to administer on-premise deployments.

What you need before you begin

 

  • You must use one of the following versions of Windows:
    • Windows 8 or Windows 8.1
    • Windows Server 2012 or Windows Server 2012 R2
    • Windows 7 SP1*
    • Windows Server 2008 R2 SP1*
  • Windows PowerShell needs to be configured to run scripts.  You only need to run this once on your computer (not every time you connect).  To enable PowerShell to run signed scripts, run the following command in an elevated Windows PowerShell Window (elevated, meaning instead of simply clicking PowerShell to open it, you must right-click PowerShell and select the option Run as Administrator).

Set-ExecutionPolicy RemoteSigned

  • TCP port 80 traffic must be allowed between your local computer and the Exchange Online servers.  Since this is the standard HTTP port for web traffic, it is almost certainly open, but in case you experience trouble connecting you should double-check this.

* You need to install the Microsoft .NET Framework 4.5 and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0.

Connect to Exchange Online (O365)

  1. On your local computer, open Windows PowerShell and run the following command.  This will then present a login box to you.  You must enter your Exchange Online username and password in this login box, and click OK.

$UserCredential = Get-Credential

  1. Run the following command.

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

  1. Run the following command.

Import-PSSession $Session

After the above is completed, the Exchange Online cmdlets are imported into your local Windows PowerShell session.   It is also a good idea to disconnect your PowerShell connection once you are through.  This can be accomplished using the following command.

Remove-PSSession $Session

 

Comments are closed.