Skip to content

Instantly share code, notes, and snippets.

@chrisbewz
Created November 12, 2025 18:53
Show Gist options
  • Select an option

  • Save chrisbewz/b9dba05f2deebbea770f66daa4838351 to your computer and use it in GitHub Desktop.

Select an option

Save chrisbewz/b9dba05f2deebbea770f66daa4838351 to your computer and use it in GitHub Desktop.
[Powershell] Removing Certificates By ThumbPrint
param(
[Parameter(Mandatory=$true)]
[string]$Thumbprint
)
$stores = @(
"Cert:\LocalMachine\My",
"Cert:\LocalMachine\Root",
"Cert:\LocalMachine\AuthRoot",
"Cert:\LocalMachine\TrustedPublisher",
"Cert:\CurrentUser\My",
"Cert:\CurrentUser\Root",
"Cert:\CurrentUser\AuthRoot",
"Cert:\CurrentUser\TrustedPublisher"
)
foreach ($storePath in $stores) {
Write-Host "Searching in: $storePath"
try {
$certificate = Get-ChildItem -Path $storePath | Where-Object {$_.Thumbprint -eq $Thumbprint}
if ($certificate) {
Write-Host "Certificate found in $storePath. Attempting to remove..."
Remove-Item -Path $certificate.PSPath -DeleteKey -Confirm:$false
Write-Host "Certificate removed from $storePath."
return # Exit after finding and removing the certificate
}
}
catch {
Write-Warning "Could not access or process store $storePath. Error: $($_.Exception.Message)"
}
}
Write-Host "Certificate with thumbprint '$Thumbprint' not found in any specified store."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment