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 14 lipca, 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

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…

2 tygodnie 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…

5 miesięcy 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…

7 miesięcy 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…

8 miesięcy ago

How to Efficiently Remove Comments from Your PowerShell Script

As part of my daily development, I create lots of code that I subsequently comment…

8 miesięcy ago

Unlocking PowerShell Magic: Different Approach to Creating ‘Empty’ PSCustomObjects

Today I saw an article from Christian Ritter, "PowerShell: Creating an "empty" PSCustomObject" on X…

9 miesięcy ago