Skip to content
Documentation
Updated 3 minutes to read
Markdown

Cleanup and Diagnostic Script – Certificate Purpose and EKU Testing

Section titled “ Cleanup and Diagnostic Script – Certificate Purpose and EKU Testing”

Remove all test certificates and the test Root CA after EKU validation testing, and diagnose any certificates that were not cleaned up as expected.

Terminal window
# Cleanup all Nodinite Certificate Purpose & EKU test certificates
Write-Host "=== Cleaning up Certificate Purpose test certificates ===" -ForegroundColor Magenta
$removed = 0
$failed = 0
# Certificate stores to clean
# Test CA is in Root store; issued certs are in My store
$stores = @(
"LocalMachine\My", # Personal certificates (6 test certs)
"LocalMachine\Root" # Trusted Root CA (test Root CA)
)
# Filter for test certificates
$filter = {
$_.Subject -like "*Nodinite-Test-*" -or
$_.Subject -like "*Nodinite Testing*" -or
$_.FriendlyName -like "Nodinite Test -*"
}
# Process each store
foreach ($store in $stores) {
Write-Host "`nCleaning $store store..." -ForegroundColor Cyan
$certs = Get-ChildItem "Cert:\$store" -ErrorAction SilentlyContinue | Where-Object $filter
foreach ($cert in $certs) {
try {
Write-Host " Removing: $($cert.Subject) [$($cert.Thumbprint)]" -ForegroundColor Gray
Remove-Item -Path "Cert:\$store\$($cert.Thumbprint)" -Force -ErrorAction Stop
$removed++
} catch {
Write-Host " Failed: $($_.Exception.Message)" -ForegroundColor Red
$failed++
}
}
}
Write-Host "`n=== Cleanup Summary ===" -ForegroundColor Green
Write-Host " Removed: $removed certificates" -ForegroundColor Cyan
Write-Host " Failed: $failed certificates" -ForegroundColor $(if ($failed -gt 0) { "Red" } else { "Green" })

If certificates are not being cleaned up as expected, use this script to scan all certificate stores and identify what Nodinite is detecting:

Terminal window
# Diagnostic: Find all test certificates with full details
Write-Host "=== Certificate Diagnostic Tool ===" -ForegroundColor Magenta
Write-Host "Searching for test certificates across all properties..." -ForegroundColor Cyan
$allCerts = @()
$stores = @(
"LocalMachine\My",
"LocalMachine\Root"
)
# Scan all certificate stores
foreach ($store in $stores) {
Write-Host "`nScanning $store..." -ForegroundColor Yellow
$count = 0
Get-ChildItem "Cert:\$store" -ErrorAction SilentlyContinue | ForEach-Object {
$allCerts += [PSCustomObject]@{
Store = $store
Subject = $_.Subject
FriendlyName = $_.FriendlyName
Thumbprint = $_.Thumbprint
NotAfter = $_.NotAfter
Issuer = $_.Issuer
}
$count++
}
Write-Host " Found $count total certificate(s) in store" -ForegroundColor Gray
}
# Filter for test certificates
Write-Host "`nFiltering for test certificates..." -ForegroundColor Yellow
$testCerts = $allCerts | Where-Object {
$_.Subject -like "*Nodinite-Test-*" -or
$_.Subject -like "*Nodinite Testing*" -or
$_.FriendlyName -like "Nodinite Test -*" -or
$_.Issuer -like "*Nodinite Testing*"
}
if ($testCerts.Count -eq 0) {
Write-Host "`nNo test certificates found. Cleanup is complete." -ForegroundColor Green
} else {
Write-Host "`nFound $($testCerts.Count) test certificate(s):" -ForegroundColor Cyan
$testCerts | Format-Table Store, Subject, Thumbprint -AutoSize -Wrap
Write-Host "`nBreakdown by store:" -ForegroundColor Cyan
$testCerts | Group-Object Store | ForEach-Object {
Write-Host " $($_.Name): $($_.Count) certificate(s)" -ForegroundColor White
}
Write-Host "`nTo remove these certificates, run the cleanup script above." -ForegroundColor Yellow
}

...

Version:
Release date: N/A
Loading...

Explore Nodinite for 30 days – completely free

  • Find out why this is the leading O&M software
  • Prove your business case
  • Test the self-service for the business side

Loading...

See how Nodinite resolves your technical issues, in a LIVE Demo!

Once you submit this request:

  • We will give you a short call to understand the issues you want to tackle.
  • Understand solutions you have tried and why were you not happy with them.
  • Book a convenient slot for a LIVE demo!

Loading...