How to delete the windows certificate using PowerShell?


To delete the Windows certificate using PowerShell, we can use the Remove-Item command.

Suppose you know the thumbprint of the certificate then to retrieve all the certificates that use that particular thumbprint, we will use the below command.

PS C:\> gci cert:\ -Recurse | where{$_.Thumbprint -eq

Output

To remove the certificates, we will pipeline the Remove-Item command.

PS C:\> gci cert:\ -Recurse | where{$_.Thumbprint -eq
'920B033462B2FE268E6F9679F8621AEDC78D506C'} | Remove-Item -Force -Verbose

Output

Or if you have the Subject name, then instead of the Thumbprint property, you can use the subject name.

PS C:\> gci cert:\ -Recurse | where{$_.Subject -eq "DemoCert"} | Remove-Item -Force - Verbose

To remove the certificate on the remote servers, you can use the Invoke-Command.

Invoke-Command -ComputerName $Server -ScriptBlock{
   gci cert:\ -Recurse | where{$_.Subject -eq "DemoCert"} |
Remove-Item -Force -Verbose
}

Updated on: 02-Sep-2021

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements