Sample code for 30+ languages & platforms
PowerShell Requires Chilkat v10.1.2+

Open Smartcard Certificate Store (or from USB Token)

See more Certificates Examples

Demonstrates how to open the certificate store of the smart card currently in the reader (or the USB token). Iterates over the certs found on the smartcard.

Chilkat PowerShell Downloads

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

$success = $false

$certStore = New-Object Chilkat.CertStore

#  Access the certificates on the smart card or USB token via the Chilkat certificate store class.
#  Note: Always pass the empty string to OpenSmartcard.

$success = $certStore.OpenSmartcard("")
if ($success -eq $false) {
    $($certStore.LastErrorText)
    exit
}

$($certStore.LastErrorText)

#  Iterate over certificates on the smartcard.
$cert = New-Object Chilkat.Cert
$i = 0
$numCerts = $certStore.NumCertificates
$("numCerts = " + $numCerts)

while (($i -lt $numCerts)) {
    $certStore.GetCert($i,$cert)
    $($cert.SubjectCN)
    $($cert.SerialNumber)
    if ($cert.IsRsa() -eq $true) {
        $("key type is RSA")
    }

    if ($cert.IsEcdsa() -eq $true) {
        $("key type is ECDSA")
    }

    $("has private key: " + $cert.HasPrivateKey())
    $("----")
    $i = $i + 1
}