Knowledge Basemagnifier-glass

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

How can we help you?

Connect to Exchange server via PowerShell

If you have not installed Exchange management tools on your local computer, you can go with Windows PowerShell to create a remote PowerShell session to connect an Exchange server. It involves a simple three-step process, where you need to provide appropriate credentials, necessary connection settings, and then import the Exchange cmdlets into your local Windows PowerShell session.

Things to know before starting:

1. Estimated time for completion: Less than 5 minutes

2. Supported Operating System:

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

For older versions of Windows, you need to install the Microsoft.NET Framework 4.5 or later and then an updated version of the Windows Management Framework: 3.0, 4.0, or 5.1 (only one).

3. By default Windows PowerShell is not configured to run scripts and you will get the below error when you try to connect

"Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files"

Run the below command in Windows PowerShell Run as administrator):

Command: Copy & Paste it on EMS

Set-ExecutionPolicy RemoteSigned

powershell-configuration

Configure this setting only once on your computer, not every time you connect.

Connect to a remote Exchange server

1. Open Windows PowerShell, and run the below command on your local computer.

Command: Copy & Paste it on EMS

$UserCredential = Get-Credential

windows-powershell-credential

2. Enter your user principal name (UPN) (for example, abc@company.com), password in the Windows PowerShell Credential Request dialog box and then click OK.

2. Connecting to Exchange Server:

  • a. To connect to Exchange Server 2010, 2013, 2016 and 2019:

    Replace with the fully qualified domain name of your Exchange server (Example: user01@company.com) and run the below command:

    Command: Copy & Paste it on EMS

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http:///PowerShell/ -Authentication Kerberos -Credential $UserCredential

    Note: The ConnectionUri value is HTTP, not HTTPS.

    To connect via https:// -Authentication Kerberos should not be provided

    Command: Copy & Paste it on EMS

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<ServerFQDN> /powershell/ -Credential $ UserCredential

  • b. To connect to Exchange Online:

    Command: Copy & Paste it on EMS

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

    connect-to-Exchange

Notes:

3. Run the following command

Command: Copy & Paste it on EMS

Import-PSSession $Session –DisableNameChecking

disconnect-remote-powershell

Note: Disconnect the remote PowerShell session when you're completed. If you close the Windows PowerShell window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you'll need to wait for the sessions to expire. To disconnect the remote PowerShell session, run the below command.

Command: Copy & Paste it on EMS

Remove-PSSession $Session

run-exchange-management

Below command can be used to run Exchange management though PowerShell. Start Windows PowerShell and load the Exchange snap-in from there by executing the cmdlet below:

Command: Copy & Paste it on EMS

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

Test to make sure this worked:

After Step 3, the Exchange cmdlets are imported into your local Windows PowerShell session and tracked by a progress bar. If you don't receive any errors, then the connection will be successful. A quick test to run an Exchange cmdlet (for example, Get-Mailbox) and review the results.

If you receive errors, check the following requirements:

  • A common problem is an incorrect password. Run the three steps again, and pay close attention to the user name and password that you have to enter in Step 1.
  • The account you use to connect to the Exchange server needs to be enabled for remote PowerShell access. For more information, see Control remote PowerShell access to Exchange servers.
  • TCP port 80 traffic needs to be open between your local computer and the Exchange server. It's probably open, but it's something to consider if your organization has a restrictive network access policy.


Live Chat

Hi, May I help you?

Hide Chat Now