Created
November 12, 2025 18:53
-
-
Save chrisbewz/b9dba05f2deebbea770f66daa4838351 to your computer and use it in GitHub Desktop.
[Powershell] Removing Certificates By ThumbPrint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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