I recently rebuilt my PKI and I would like to delete the certificates that were issued to all client machines across my network. Sounds like a job for Powershell! So I wrote this script to be distributed by GPO, ran from SysVol, and triggered on client machines at startup:
set-location cert:\LocalMachine\My
$certname = $env:COMPUTERNAME + ".domain.com"
get-item * | %{
if($_.issuer -like "CN=IssuingCA*" -and $_.DnsNameList.unicode -like $certname) { remove-item .\$_.Thumbprint -Force }
}
From an elevated command prompt:
- When Ran, the script gives no output (simply a new terminal line). It returns no errors and the Certificate is not deleted.
- When the argument
-WhatIf
is added to theRemove-Item
command in the script, again no errors and the Certificate is not deleted. - When Remove-Item .\CERTIFICATE-THUMBPRINT -Force is ran, the certificate is deleted.
Is this a permissions issue? Is there a smarter/simpler way to do this?
Thanks!