Applications Systems

Self-signed Certificate PowerShell script for AppInsight for Exchange

This KB includes a self-signed certificate PowerShell script for AppInsight for Exchange. The script automatically prompts for the IP Address of the Exchange server and sets the CN and expiration dates to their correct values.

First published date

11/29/2018 10:37 PM

Last published date

10/17/2025 10:42 PM

Overview

You can use a self-signed certificate PowerShell script for AppInsight for Exchange to automatically prompt for the IP Address of the Exchange server and sets the CN and expiration dates to their correct values.

Product section

Server Application Monitor

Resolution

Run the following script on the Exchange server, using an elevated PowerShell session.

$IPAddress = Read-Host "Enter the IP Address of the Exchange server"
$ExpDays = "3650"
$FriendlyName = "$IPAddress" + "_Solarwinds_Exchange_Zero_Configuration"
$name = new-object -com "X509Enrollment.CX500DistinguishedName.1"
$name.Encode("CN=$FriendlyName", 0)

$key = new-object -com "X509Enrollment.CX509PrivateKey.1"
$key.ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
$key.KeySpec = 1
$key.Length = 1024
$key.SecurityDescriptor = "D:PAI(A;;0xd01f01ff;;;SY)(A;;0xd01f01ff;;;BA)(A;;0x80120089;;;NS)"
$key.MachineContext = 1
$key.Create()

$serverauthoid = new-object -com "X509Enrollment.CObjectId.1"
$serverauthoid.InitializeFromValue("1.3.6.1.5.5.7.3.1")
$ekuoids = new-object -com "X509Enrollment.CObjectIds.1"
$ekuoids.add($serverauthoid)
$ekuext = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage.1"
$ekuext.InitializeEncode($ekuoids)

$cert = new-object -com "X509Enrollment.CX509CertificateRequestCertificate.1"
$cert.InitializeFromPrivateKey(2, $key, "")
$cert.Subject = $name
$cert.Issuer = $cert.Subject
$cert.NotBefore = get-date
$cert.NotAfter = $cert.NotBefore.AddDays($ExpDays)
$cert.X509Extensions.Add($ekuext)
$cert.Encode()

$enrollment = new-object -com "X509Enrollment.CX509Enrollment.1"
$enrollment.InitializeFromRequest($cert)
$enrollment.CertificateFriendlyName = $FriendlyName
$certdata = $enrollment.CreateRequest(0)
$enrollment.InstallResponse(2, $certdata, 0, "")