This is just a quick little script to delete a certificate using powershell. It’s not as flexible as one might want it to be but should get you started. Plus, it could be optimized a bit, but it gets the job done!
You’ll notice the line:
new-object System.Security.Cryptography.X509Certificates.X509Store "My","CurrentUser"
The “My” is the StoreName (AddressBook, AuthRoot, CertificateAuthority, Disallowed, My, Root, TrustedPeople, TrustedPublisher). See http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename.aspx for more info.
“CurrentUser” is the StoreLocation with “CurrentUser” or “LocalMachine” the only two options at present. See http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storelocation.aspx for more info.
param
(
[parameter(Mandatory=$true)][string]$certPattern
)
write-host "`nCertificate search pattern = '$certPattern'"
$store = new-object System.Security.Cryptography.X509Certificates.X509Store "My","CurrentUser"
$store.Open("ReadWrite")
$certs = $store.Certificates
foreach ($cert in $certs)
{
if ($cert -like $certPattern)
{
write-host "Deleting: "$cert.Thumbprint $cert.Subject
$store.Remove($cert)
}
}
$store.Close()