EdbMails EDB Recovery and Migration software
  • Reseller
  • Free Trial
  • Video Tutorials
  • Support
  • FAQ
  • Free Tools
  • Knowledge Base
  • Products
    Exchange EDB / Email Recovery Tools
    • EDB Recovery and MigrationRecover EDB to PST, EDB to Office 365 and Exchange NO Duplicate Migration
    • OST Recovery and MigrationRecover OST to PST, OST to Office 365 and Exchange Migration
    • PST Recovery and MigrationRecover Outlook PST, PST to Office 365 and Exchange Migration
    • MBOX Export and MigrationExport MBOX to PST, MBOX to Office 365 and Exchange Migration
    • NSF Export and MigrationExport NSF to PST, NSF to Office 365 and Exchange Migration
    Exchange and Office 365 Migration
    • Exchange Server MigrationMigrate Exchange 2007, 2010, 2013, 2016, 2019 to Office 365 tenants. Also, migrate between Exchange servers and PST
    • Office 365 MigrationMigrate Source Office 365 tenants to Destination Office 365 tenants. Also, migrate to Exchange Server and PST
    • IMAP Email Backup & MigrationMigrate all IMAP email servers (Gmail, Zimbra, Zoho, Yahoo etc.), Office 365, Exchange and Backup to Outlook PST
    • SharePoint Online MigrationMigrate documents, files and folders from SharePoint sites
    • OneDrive for Business MigrationMigrate documents, files and folders from OneDrive
    • Microsoft Teams MigrationMigrate Teams, documents, files and folders etc.
    Exchange and Office 365 Backup
    • Office 365 BackupIncremental, Granular, Encrypted and Compressed Office 365 Mailboxes Backup
    • Exchange Server BackupIncremental, Granular, Encrypted and Compressed Exchange Mailboxes Backup
    • SharePoint, OneDrive & Teams BackupBackup Online site collections, Team sites, Office 365 groups, all documents etc.
    • Duplicate Remover - Office 365 & Exchange Remove duplicate emails, calendars, contacts, journal etc. from Office 365 and Exchange
    • GAL and All Address Lists migrationDirectly migrate Exchange and Office 365 Global address list and Address Lists items
    Go to products
  • Pricing
  • Features
  • Download
  • Account

Knowledge Basemagnifier-glass

Get an instant help and tips on how to use and get the most out of your EdbMails tools.

  • Video Tutorials
  • FAQ's
  • Support
  • Personalized Demo

How can we help you?

Blog » Login - Exchange, Office 365 and more

Connect to an Exchange server by using PowerShell

Problem:

You want to use PowerShell to set up a remote connection to an Exchange server.

Solution:

With this article you can:

  • Connect to your on-premises Exchange servers by using a remote PowerShell session.
  • Set up a remote PowerShell connection to your Exchange Online organization.
  • Troubleshooting the PowerShell errors.

Connect to on-premises Exchange server

  1. Verify the requirements for on-premises Exchange Server
  2. Start Windows PowerShell in administrator mode
  3. Verify your Execution policy settings by running the below command:

    Get-ExecutionPolicy

    Change the execution policy to 'RemoteSigned' or 'Unrestricted' if it is currently set to Restricted.

    Set-ExecutionPolicy RemoteSigned

  4. Run the following command and enter the target server administrator credentials:

    $LiveCred = Get-Credential

  5. Run the following command to set up the connection to your Exchange server 2010, 2013, 2016 and 2019

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<target-server-address>/powershell/ -Credential $LiveCred

    Please note that the aforementioned approach is not always applicable. Depending on the setup of your target environment, you might need to use http rather than https to connect, specify the authentication method as an option (-Authentication Kerberos) and so on. The following example demonstrates these requirements:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<target-server-address>/powershell/ -Credential $LiveCred -Authentication Kerberos

    In addition, you must specify some Options instead of New-PSSession and pass it as a variable. For a sample of how to use the advanced option for a session, refer to the 'Troubleshooting the PowerShell errors' section below.

  6. Run the following command to start the connection

    Import-PSSession $Session

  7. Run the following command to disconnect Exchange server

    Remove-PSSession $Session

Furthermore, you can launch Windows PowerShell and load the Exchange snap-in from there, if you are logged in directly to an on-premises Exchange server and for some reason are unable to run the Exchange Management Shell:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

Connect to Exchange Online (Microsoft 365)

  1. Verify the requirements for Exchange Online (Microsoft 365)
  2. Start Windows PowerShell in administrator mode
  3. Verify your Execution policy settings by running the below command:

    Get-ExecutionPolicy

    The execution policy is normally set to Restricted. It is advised to configure the policy to RemoteSigned in order to connect to Exchange Online with PowerShell successfully:

    Set-ExecutionPolicy RemoteSigned

  4. Run the following command and enter your Microsoft 365 global admin credentials:

    $LiveCred = Get-Credential

  5. Run the following command to connect to Exchange Online (Microsoft 365)

    Connect-ExchangeOnline -Credential $LiveCred

    Use the Connect-ExchangeOnline cmdlet without the -Credential parameter if you're connecting to Exchange Online using an account that has MFA enabled. Provide your credentials in a pop-up window.

    Note that if you have your account with MFA enabled, the cmdlet doesn't accept the -Credential parameter.

  6. Run the following command to disconnect Exchange Online

    Disconnect-ExchangeOnline

Troubleshooting the PowerShell errors

Invalid credentials

You may get the following error when you attempt to connect to an On-Premises Exchange server

Connecting to remote server <ServerName> failed with the following error message : The user name or password is incorrect.

To resolve the error, you need to enter the correct login credentials. When you login to Exchange Online, a similar error may appear.

Connecting to remote server ps.outlook.com failed with the following error message : [ClientAccessServer=XXXXX,BackEndServer=YYYYY,RequestId=ZZZZZ, TimeStamp=MM/DD/YYYY H:MM:SS PM] Access Denied

In this situation, you should also carefully check the provided credentials for spelling errors.

Issues with certificates

If you encounter the following certificate errors, you will be unable to set up a remote connection by using the methods described previously in this article.

Connecting to remote server <ServerName> failed with the following error message : The server certificate on the destination computer <ServerName> has the following errors:
The SSL certificate is signed by and unknown certificate authority.
The SSL certificate contains a common name (CN) that does not match the hostname.

To bypass the certificate validation checks, use the New-PSSessionOption cmdlet instead:

$SessionOpt = New-PSSessionOption -SkipCACheck:$true -SkipCNCheck:$true -SkipRevocationCheck:$true
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<target-server-address>/powershell/ -Credential $LiveCred -SessionOption $SessionOpt

After you run the cmdlet, you should be able to start a new session successfully.

Cannot recognize 'Connect-ExchangeOnline'

If you want to connect to Exchange Online using PowerShell (with the modern method), you must first install the Exchange Online PowerShell V2 module. The following error message occurs if the PowerShell V2 module is not installed:

Connect-ExchangeOnline : The term 'Connect-ExchangeOnline' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

To resolve this error, install and import the PowerShellGet and Exchange Online PowerShell V2 modules. You can accomplish this activity by using the following cmdlets:

Install-Module -Name ExchangeOnlineManagement;
Import-Module -Name ExchangeOnlineManagement

Install the prerequisite package provider prompted by PowerShell before you install the new Exchange Online Management module.

You may need to update your registry to proceed if you encounter the "Unable to download from URI" issue at this stage (i.e., while trying to download the NuGet provider). To solve the problem, the .NET Framework must support strong cryptography. Refer to the Microsoft website for more details.

Click here to know the steps for Exchange migration using EdbMails

Click here to know the steps for Exchange Online (Office 365) migration using EdbMails



Related topics:

  • Do I need to set Impersonation Rights to each and every user account
  • Invalid user or password
  • Unexpected XML Content
  • Error: ErrorInvalidSerializedAccessToken
  • ErrorQuotaExceeded
  • Could not map Exchange web service folder - Error
  • Login issues - Not Found Error
  • Free/Busy status migration
  • Steps to recreate Outlook profiles after the migration
  • How to allow PowerShell to connect to Exchange Server via IP address?
hidden msg

EdbMails Demo / Trial Version

Step 1. Download and install EdbMails

Step 2. Click the 'Start Your Free Trial' button

Demo login EdbMails

  • Home
  • Features
  • Pricing
  • Support
  • Download
  • Sitemap
  • FAQ
  • Video Tutorials
  • Technical Support
  • Live Chat
  • Contact Us
Shifttocloud Inc.
Rehoboth Beach, DE
United States
+1 (302) 416-3056

Privacy Policy | Terms of Use | GDPR | Security | Press Releases

© 2023 Shifttocloud Inc.

Live Chat

Hi, May I help you?

Hide Chat Now