Categories: Exchange

Microsoft Exchange – Connecting to remote server failed with the following error message

Connecting to Microsoft Exchange via PowerShell is a standard administrative tasks since Exchange 2007 was released.  It's available in all Exchange editions Exchange 2007, Exchange 2010, Exchange 2013, Exchange 2016 and last but not least Microsoft Office 365. To properly manage Exchange you simply need the PowerShell connectivity. While using PowerShell locally doesn't do much checks, during remote connection a lot more things gets checked. One of which are certificates.

Problem Description

During establishing remote connection to Exchange PowerShell using New-PsSession following error is received:

[ERROR] New-PSSession : [mail1.domain.local] Connecting to remote server mail1.domain.local failed with the following error message : The server certificate on the destination computer (mail1.domain.loca:443) has the following errors:     

[ERROR] The SSL certificate contains a common name (CN) that does not match the hostname. For more information, see the about_Remote_Troubleshooting Help topic.

Another error that can show up during PowerShell connectivity:

[ERROR] New-PSSession : [mail1.domain.local] Connecting to remote servermail1.domain.local failed with the following error message : The server certificate on the destination computer (mail1.domain.local:443) has the following errors:

[ERROR] The SSL certificate could not be checked for revocation. The server used to check for revocation might be unreachable.

[ERROR] For more information, see the about_Remote_Troubleshooting Help topic.

Solution

While you should always use proper certificates on your servers that's not always the case. If you are sure about the server you're connecting to you can use New-PSSessionOption as part of New-PSSession connectivity.

$sessionOption = New-PSSessionOption -SkipRevocationCheck -SkipCACheck -SkipCNCheck

$EXOSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $URL -Credential $Credentials -Authentication $Authentication -AllowRedirection -Name $sessionName -SessionOption $sessionOption

As you can you see in the example above there are 3 very useful switches for New-PSSessionOption: SkipRevocationCheck, SkipCACheck, SkipCNCheck. Those are in case you get other similar errors when connecting to PowerShell remotely and should solve most of the certificates issues that may arise during connection to powershell. Just make sure the server is trusted. Finally proceed with standard Import-PSSession $EXOSession -AllowClobber.

This post was last modified on July 14, 2016 08:12

Przemyslaw Klys

System Architect with over 14 years of experience in the IT field. Skilled, among others, in Active Directory, Microsoft Exchange and Office 365. Profoundly interested in PowerShell. Software geek.

Share
Published by
Przemyslaw Klys

Recent Posts

Upgrade Azure Active Directory Connect fails with unexpected error

Today, I made the decision to upgrade my test environment and update the version of…

5 days ago

Mastering Active Directory Hygiene: Automating Stale Computer Cleanup with CleanupMonster

Have you ever looked at your Active Directory and wondered, "Why do I still have…

4 months ago

Active Directory Replication Summary to your Email or Microsoft Teams

Active Directory replication is a critical process that ensures the consistent and up-to-date state of…

8 months ago

Syncing Global Address List (GAL) to personal contacts and between Office 365 tenants with PowerShell

Hey there! Today, I wanted to introduce you to one of the small but excellent…

1 year ago

Active Directory Health Check using Microsoft Entra Connect Health Service

Active Directory (AD) is crucial in managing identities and resources within an organization. Ensuring its…

1 year ago

Seamless HTML Report Creation: Harness the Power of Markdown with PSWriteHTML PowerShell Module

In today's digital age, the ability to create compelling and informative HTML reports and documents…

1 year ago