Sample code for 30+ languages & platforms
PowerShell

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

$certStore = New-Object Chilkat.CertStore

# This example will search the certs on connected USB tokens and smartcards.
$argNotUsed = ""
$success = $certStore.OpenSmartcard($argNotUsed)
if ($success -eq $false) {
    $($certStore.LastErrorText)
    exit
}

# Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
$hexSerial = "48FC93B46055948D36A7C98A89D69416"
$json = New-Object Chilkat.JsonObject
$json.UpdateString("serial",$hexSerial)

$cert = New-Object Chilkat.Cert
$success = $certStore.FindCert($json,$cert)
if ($success -eq $true) {
    # Show the serial number and subject CN
    $("Found: " + $cert.SerialNumber + ", " + $cert.SubjectCN)
}
else {
    $("Not found.")
}