How to Connect to Office 365 Exchange with Powershell Command – Solved
Connect to Exchange Online with Remote Powershell
Office 365 Exchange Online PowerShell allows you to access your O365 Account settings with the command line. On your local computer, you can use Windows PowerShell, that will create a remote PowerShell session to O365 Exchange Online. The simple 3-step process to Connect to Office 365 Exchange Online with Powershell, where you enter your Outlook 365 credentials, next set the connection settings, and then import the ‘Exchange Online cmdlets’ into your local Windows PowerShell session to use.
Note: In case want to use multi-factor authentication i.e. MFA for connecting to Exchange Online with Remote Powershell, then download Office 365 Remote PowerShell Module. To know more visit: Connect to Exchange Online PowerShell using multi-factor authentication. Also, if you have opted Exchange Online Protection (EOP), and protecting on-premises mailboxes using this service, then check the connection instructions here.
Extra Things to Know before you Start
- Time taken to establish the connection: Approx. 5 mins
- Windows OS Supported: Windows 10, Windows 8.1, Windows Server 2016 / 2012 / 2012R2, Windows 7 SP1, Windows Server 2008 R2 SP1.
For Older Windows Version, Microsoft.NET Framework 4.5 or later and Windows Management Framework: 3.0, 4.0, or 5.1 (any one) must be installed on OS.
- The Configuration of Windows PowerShell needed to be done to run scripts. Otherwise, an error will prompt while connecting to Exchange Online with remote Powershell
“Files cannot be loaded because running scripts are disabled on this system. Provide a valid certificate with which to sign the files”.
Download PowerShell scripts signed by a trusted publisher and run the below command in Windows PowerShell (choose Run as Admin to open) to enable.
Set-ExecutionPolicy RemoteSigned (Configure this setting only once)
How to Connect to Office 365 Exchange Online with Powershell- Steps
Step1. Open PowerShell Command on your Computer / PC and run the Powershell command to connect Exchange online using Powershell command.
$LiveCredential = Get-Credential
Windows PowerShell Credential Request window will prompt, type O365 account User name & password, and next click on the OK button.
Step2. Run the following command.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $LiveCredential -Authentication Basic -AllowRedirection
Points to remember:
- ConnectionUri value used for O365 operated by 21Vianet is:
- ConnectionUri value used for O365 Germany is:
- Incase user is behind a proxy server, first run: $ProxyOptions = New-PSSessionOption -ProxyAccessType ,
Here ProxyAccessType value is IEConfig / WinHttpConfig / AutoDetect.
Add parameter and value in the end of the $Session = … command: -SessionOption $ProxyOptions.
To know more, visit New-PSSessionOption.
Step3. Next, run the below command.
Now You are connected to Exchange Online with Remote Powershell. In case Microsoft Online Services Sign-in Assistant is installed on your system, execute the following command:
Connect-MsolService –Credential $LiveCred
Note: Make sure you disconnect the remote PowerShell session when you’re finished. To disconnect, run below command.
How to Check it Worked for You or Not?
Once Step 3 is performed, the Office 365 Exchange Online cmdlets will be imported within Windows PowerShell session and can be tracked by the progress bar. No error received, means connecting to Exchange Online with Remote PowerShell established successfully. To test, run a quick Exchange Online cmdlet, i.e., Get-Mailbox to see the result.
Getting error check below:
- Most common problem found is incorrect O365 account password. Run the 3 – Step Process again and in Step 1 recheck the user name and password twice before moving to the next step to connect Office 365 with remote Powershell.
- Sometimes to prevent denial-of-service attacks, you’re restricted to open remote PowerShell outside Exchange Online organization.
- Remote PowerShell for the account used must be enabled for connecting to Exchange Online.
- Between your System & Office 365, TCP port 80 traffic must be open. Mostly it is open, but sometimes it is close because the organization enabled a restrictive Internet access policy.
How to Backup Office 365 Mails & Documents on Local Computer?
SysTools Office 365 Mailbox Backup Tool to create a copy of O365 Exchange Online Account on the local computer. Once done you can also archive it to PST file format. The software helps to perform both full and granular backup of multiple O365 user/admin account on the local computer. The advance explorer option will let you preview entire backed up O365 Mails & Documents. To know more how to backup, see: Office 365 Backup Solutions For Mailbox Items | 10 Min Setup.
In this article we have come up with 3 – Step procedure to connect to Exchange Online with Remote Powershell. Now, days no data is secure neither on cloud nor on Local PC or computer. An extra level of protection will help you to secure your Office 365 data in case you lose your data. Moreover, SysTools Office 365 Backup Tool is the best utility to secure your Office 365 cloud data on your Computer or on the local server or on the external hard drive.