Remove Certificates using PowerShell

1. Process

This article details the way to remove certificates using PowerShell.

The Cmdlet used to delete certificates is Remove-Item

 

Let’s take for example the following certificate: SCOM-ECO.

 

To check if the certificate is present in the store of the machine:

removecertps01

 

removecertps02

 

removecertps03

 

removecertps04

 

removecertps05

 

Launch the PowerShell Console.

removecertps06

 

removecertps07

 

removecertps08

 

removecertps09

 

removecertps10

 

 

2. PowerShell Script

If (Test-Path 'Cert:\LocalMachine') {
    Set-Location Cert:\LocalMachine
}

Else {
    Write-Host 'Error - Cert:\LocalMachine path does not exist'
    Exit
}



Try {
    Get-ChildItem -Recurse | Where-Object {$_.Subject -eq "CN=SCOM-ECO, DC=dom, DC=net"} | Remove-Item
    Write-Host "Certificates removed"
}

Catch {
    Write-Host "Exception caught in removing certificate"
    Exit
}