Skip to content

Commit 5ace923

Browse files
authored
Merge pull request #1626 from microsoft/lusassl-MonitorExchangeAuthCertMarch23Adjustments
Use shared TrustAnyCertificateCallback function in MonitorExchangeAuthCertificate script
2 parents 083b413 + 7a952dc commit 5ace923

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

Admin/MonitorExchangeAuthCertificate/MonitorExchangeAuthCertificate.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ function Main {
305305
Write-Host ("Please check if the test message was received by the following recipient(s): $($SendEmailNotificationTo)")
306306
} else {
307307
Write-Host ("We hit an exception while processing your test email message. Please check the log file") -ForegroundColor Yellow
308+
Write-Host ("`n$($Error[0].Exception.Message)") -ForegroundColor Red
308309
}
309310
return
310311
}
@@ -434,7 +435,7 @@ function Main {
434435
Write-Host ("We couldn't validate if the Auth Certificate is properly configured because $($authCertStatus.NumberOfUnreachableServers) servers were unreachable.") -ForegroundColor Yellow
435436
Write-Host ("The unreachable servers are: $([string]::Join(", ", $authCertStatus.UnreachableServersList))") -ForegroundColor Yellow
436437
} elseif ($stopProcessingDueToHybrid) {
437-
Write-Host ("We have not made any configuration change because because Exchange Hybrid has been detected in your environment.") -ForegroundColor Yellow
438+
Write-Host ("We have not made any configuration change because Exchange Hybrid has been detected in your environment.") -ForegroundColor Yellow
438439
Write-Host ("Please rerun the script using the '-IgnoreHybridConfig `$true' parameter to perform the renewal action.") -ForegroundColor Yellow
439440
Write-Host ("It's also required to run the Hybrid Configuration Wizard (HCW) after the primary Auth Certificate was replaced.") -ForegroundColor Yellow
440441
} else {

Shared/EMailFunctions/Send-EwsMailMessage.ps1

+3-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Licensed under the MIT License.
33

44
. $PSScriptRoot\..\Invoke-CatchActionError.ps1
5+
. $PSScriptRoot\..\CertificateFunctions\Enable-TrustAnyCertificateCallback.ps1
56

67
function Send-EwsMailMessage {
78
[CmdletBinding()]
@@ -57,19 +58,6 @@ function Send-EwsMailMessage {
5758
Write-Verbose "Calling: $($MyInvocation.MyCommand)"
5859
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
5960

60-
$trustAllCertsPolicyClass = @"
61-
using System.Net;
62-
using System.Security.Cryptography.X509Certificates;
63-
public class TrustAllCertsPolicy : ICertificatePolicy {
64-
public bool CheckValidationResult(
65-
ServicePoint srvPoint, X509Certificate certificate,
66-
WebRequest request, int certificateProblem) {
67-
return true;
68-
}
69-
}
70-
"@
71-
Add-Type -TypeDefinition $trustAllCertsPolicyClass -ErrorAction Stop
72-
7361
if (Test-Path $EwsManagedAPIAssemblyPath) {
7462
Write-Verbose ("EWS Managed API Assembly was found under: $($EwsManagedAPIAssemblyPath)")
7563
Add-Type -Path $EwsManagedAPIAssemblyPath
@@ -80,8 +68,8 @@ function Send-EwsMailMessage {
8068
}
8169
} process {
8270
if ($IgnoreCertificateMismatch) {
83-
Write-Verbose ("IgnoreCertificateMismatch was used -policy will be set to: TrustAllCertsPolicy")
84-
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
71+
Write-Verbose ("IgnoreCertificateMismatch was used - policy will be set to: TrustAnyCertificate")
72+
Enable-TrustAnyCertificateCallback
8573
}
8674

8775
try {

0 commit comments

Comments
 (0)