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.
Cleanup Script
Section titled “ Cleanup Script”# Cleanup all Nodinite Certificate Purpose & EKU test certificatesWrite-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 storeforeach ($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 GreenWrite-Host " Removed: $removed certificates" -ForegroundColor CyanWrite-Host " Failed: $failed certificates" -ForegroundColor $(if ($failed -gt 0) { "Red" } else { "Green" })Diagnostic Script
Section titled “ Diagnostic Script”If certificates are not being cleaned up as expected, use this script to scan all certificate stores and identify what Nodinite is detecting:
# Diagnostic: Find all test certificates with full detailsWrite-Host "=== Certificate Diagnostic Tool ===" -ForegroundColor MagentaWrite-Host "Searching for test certificates across all properties..." -ForegroundColor Cyan
$allCerts = @()$stores = @( "LocalMachine\My", "LocalMachine\Root")
# Scan all certificate storesforeach ($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 certificatesWrite-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}Next Steps
Section titled “ Next Steps”- Return to FAQ - Certificate Purpose and EKU Testing Scenarios to confirm all validation checklist items are complete