File tree Expand file tree Collapse file tree
Admin/MonitorExchangeAuthCertificate/ConfigurationAction
Shared/CertificateFunctions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -209,11 +209,14 @@ function New-ExchangeAuthCertificate {
209209 } else {
210210 Write-Verbose " Creating a default self-signed certificate with a lifetime of 5 years"
211211 $certObject = New-ExchangeCertificate @newAuthCertificateParams
212+
212213 $newAuthCertificate = [PSCustomObject ]@ {
213214 Thumbprint = $certObject.Thumbprint
214215 Subject = $certObject.Subject
216+ RawData = $certObject.RawData # We need to include RawData in case the deserialization of the cert object fails
215217 }
216218 }
219+ Write-Verbose " Certificate with thumbprint: $ ( $newAuthCertificate.Thumbprint ) was generated"
217220 Start-Sleep - Seconds 5
218221 } else {
219222 $newAuthCertificateParams.GetEnumerator () | ForEach-Object {
@@ -240,7 +243,7 @@ function New-ExchangeAuthCertificate {
240243
241244 if ($null -ne $newAuthCertificate ) {
242245 $operationSuccessful = $true
243- if ($null -ne $newAuthCertificate.Thumbprint ) {
246+ if (-not ([ System.String ]::IsNullOrWhiteSpace( $newAuthCertificate.Thumbprint )) ) {
244247 Write-Verbose (" Certificate object successfully deserialized" )
245248 [string ]$newAuthCertificateThumbprint = $newAuthCertificate.Thumbprint
246249 } else {
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ function Import-ExchangeCertificateFromRawData {
2222 Write-Verbose (" Going to process '$ ( $ExchangeCertificates.Count ) ' Exchange certificates" )
2323
2424 foreach ($c in $ExchangeCertificates ) {
25+ if ($null -eq $c.RawData ) {
26+ Write-Verbose " Skipping certificate because RawData is null"
27+ continue
28+ }
29+
2530 # Initialize X509Certificate2 class
2631 $certObject = New-Object ' System.Security.Cryptography.X509Certificates.X509Certificate2'
2732 # Use the Import() method to import byte[] RawData
You can’t perform that action at this time.
0 commit comments