ExportAuthCert.ps1 fails because Auth Certificate is not exporting on line 7 on Exchange 2013 CU21

Diamond IT 11 Reputation points
2020-11-17T21:51:29.3+00:00

I'm trying to follow the steps listed here and getting stuck on step 3 while running ExportAuthCert.ps1:

$thumbprint = (Get-AuthConfig).CurrentCertificateThumbprint  
if((test-path $env:SYSTEMDRIVE\OAuthConfig) -eq $false)  
{  
   md $env:SYSTEMDRIVE\OAuthConfig  
}  
cd $env:SYSTEMDRIVE\OAuthConfig  
$oAuthCert = (dir Cert:\LocalMachine\My) | where {$_.Thumbprint -match $thumbprint}  
$certType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert  
$certBytes = $oAuthCert.Export($certType)  
$CertFile = "$env:SYSTEMDRIVE\OAuthConfig\OAuthCert.cer"  
[System.IO.File]::WriteAllBytes($CertFile, $certBytes)  

If I look at the value of $oAuthCert after line 7, it returns nothing. Line 8 doesn't throw an error, but line 9 does when it tries to export $oAuthCert to a file (since it is null).

You cannot call a method on a null-valued expression.
At C:\users\jdale\desktop\ExportAuthCert.ps1:9 char:1

  • $certBytes = $oAuthCert.Export($certType)
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : InvalidOperation: (:) [], RuntimeException
  • FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "WriteAllBytes" with "2" argument(s): "Value cannot be null.
Parameter name: bytes"
At C:\users\jdale\desktop\ExportAuthCert.ps1:11 char:1

  • [System.IO.File]::WriteAllBytes($CertFile, $certBytes)
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
  • FullyQualifiedErrorId : ArgumentNullException

When I look through the certificate store, I do not find any certificate matching the thumbprint that was returned on the first line. There must be some way to update that thumbprint, anyone know how?

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,604 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,076 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,439 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Diamond IT 11 Reputation points
    2020-11-17T22:12:46.737+00:00
    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.