---
title: FAQ - Duplicate Certificate Detection and Management
description: Detect and manage duplicate certificates in Nodinite. Learn why duplicates matter, how to find them, and best practices for certificate renewal and cleanup.
---

# FAQ - Duplicate Certificate Detection Testing Scenarios

Validate [Duplicate Certificate Detection][Duplicate Certificate Detection] monitoring with automated PowerShell test scripts covering all detection scenarios - from same-store duplicates and cross-store issues to high-risk multiple private key scenarios.

**What's on This Page:**

* **5 Test Scenarios** - Automated PowerShell 7 scripts for Same Store Duplicates, Multiple Private Keys, Cross-Store Duplicates, Threshold Testing, and Proper Renewal Cleanup
* [Batch Testing Script](#fa-tools-batch-duplicate-certificate-testing-script) - Create all test scenarios with configurable flags
* [Cleanup Script](#fa-broom-cleanup-script) - Remove test certificates after validation testing
* **Configuration Guide** - Enable duplicate detection and configure alert thresholds
* **Troubleshooting** - Resolve duplicate-specific issues (renewal confusion, private key risk)

## Why Test Duplicate Detection?

Duplicate certificate testing prevents production incidents caused by certificate selection ambiguity. Testing ensures monitoring correctly identifies:

* ⚠️ **Same-store duplicates** (WARNING) - Multiple certificates with identical Subject/SAN in same store
* ❌ **Multiple private keys** (ERROR) - High-risk scenario where applications may select wrong certificate
* ⚠️ **Cross-store duplicates** (WARNING) - Certificate exists in both LocalMachine and CurrentUser stores
* ⚠️ **Threshold exceeded** (WARNING) - Duplicate count exceeds configured maximum
* ✅ **Proper cleanup** (OK) - Old certificates removed after renewal verification

**Related Documentation:** See [Duplicate Certificate Detection][] for complete feature documentation, remediation workflows, and configuration options.

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>These scripts require <strong>PowerShell 7+</strong> with Administrator privileges for certificate store access.</p></div>
</aside>

<aside aria-label="Warning" class="nodinite-note nodinite-note--warning">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-triangle-exclamation"></i> Warning</p>
<div class="nodinite-note__content"><p>Never deploy test certificates to production environments. Always clean up after validation testing.</p></div>
</aside>

## <i class="fal fa-list-check" aria-hidden="true"></i> Testing Scenarios Overview

|#|Scenario|Purpose|[Expected State][]|Key Focus|  
|---|---|---|---|---|  
|**1**|[Same Store Duplicates](#fa-check-scenario-1-same-store-duplicates)|2+ certificates with identical Subject/SAN|⚠️ **WARNING**|Renewal overlap detection|  
|**2**|[High-Risk Duplicates](#fa-triangle-exclamation-scenario-2-high-risk-duplicates-multiple-private-keys)|Multiple certificates with private keys|❌ **ERROR**|Application selection ambiguity|  
|**3**|[Cross-Store Duplicates](#fa-network-wired-scenario-3-cross-store-duplicates)|Certificate in LocalMachine & CurrentUser|⚠️ **WARNING**|Cross-store inventory issue|  
|**4**|[Renewal Success](#fa-check-scenario-4-renewal-success-single-valid-certificate)|Old certificate removed after renewal|✅ **OK**|Proper cleanup verification|  
|**5**|[Threshold Exceeded](#fa-circle-info-scenario-5-allowed-duplicates-within-threshold)|Duplicates exceed configured maximum|⚠️ **WARNING**|Threshold enforcement|  

## <i class="fal fa-sitemap" aria-hidden="true"></i> Test Scenario Workflow

```mermaid
graph TD
    Start["<i class="fal fa-play" aria-hidden="true"></i> Start Testing"] --> Config["<i class="fal fa-cogs" aria-hidden="true"></i> Configure Scenarios"]
    Config --> S1{"<i class="fal fa-copy" aria-hidden="true"></i> Scenario 1<br/>Same Store"}
    Config --> S2{"<i class="fal fa-exclamation-triangle" aria-hidden="true"></i> Scenario 2<br/>Multiple Keys"}
    Config --> S3{"<i class="fal fa-network-wired" aria-hidden="true"></i> Scenario 3<br/>Cross-Store"}
    Config --> S4{"<i class="fal fa-check-circle" aria-hidden="true"></i> Scenario 4<br/>Proper Cleanup"}
    Config --> S5{"<i class="fal fa-list-ol" aria-hidden="true"></i> Scenario 5<br/>Threshold"}
    S1 --> V1["<i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Warning"]
    S2 --> V2["<i class="fal fa-times-circle" aria-hidden="true"></i> Error"]
    S3 --> V3["<i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Warning"]
    S4 --> V4["<i class="fal fa-circle-check" aria-hidden="true"></i> OK"]
    S5 --> V5["<i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Warning"]
    V1 --> Monitor["<i class="fal fa-eye" aria-hidden="true"></i> Monitor Results"]
    V2 --> Monitor
    V3 --> Monitor
    V4 --> Monitor
    V5 --> Monitor
    Monitor --> Validate["<i class="fal fa-check-double" aria-hidden="true"></i> Validate Alerts"]
    Validate --> Cleanup["<i class="fal fa-broom" aria-hidden="true"></i> Cleanup Test Certs"]
    Cleanup --> End["<i class="fal fa-flag-checkered" aria-hidden="true"></i> Testing Complete"]
    style S1 fill:#fff3e0
    style S2 fill:#ffebee
    style S3 fill:#fff3e0
    style S4 fill:#e8f5e9
    style S5 fill:#fff3e0
    style V1 fill:#ffe0b2
    style V2 fill:#ffcdd2
    style V3 fill:#ffe0b2
    style V4 fill:#c8e6c9
    style V5 fill:#ffe0b2
```

*Diagram: Duplicate certificate detection test workflow showing scenario configuration, expected states, and monitoring verification process with color-coded severity levels.*

## <i class="fal fa-vial" aria-hidden="true"></i> Test Scenarios

### <i class="fal fa-check" aria-hidden="true"></i> Scenario 1: Same Store Duplicates

**Purpose**: Validate detection of multiple certificates with identical Subject/SAN in the same store.

**Configuration**:

|Setting|Value|Rationale|  
|---|---|---|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Certificate Type**|Self-signed (test certificates)|Creates controlled duplicate scenario|  
|<i class="fal fa-tag" aria-hidden="true"></i> **Subject**|`CN=duplicate.test.com`|Identical Subject for both certificates|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> **Store Location**|`Cert:\LocalMachine\My`|Same store for both certificates|  
|<i class="fal fa-hashtag" aria-hidden="true"></i> **Certificate Count**|2 certificates|Simulates renewal overlap|  
|<i class="fal fa-key" aria-hidden="true"></i> **Private Keys**|Both have private keys initially|Tests detection logic|  
|<i class="fal fa-calendar-day" aria-hidden="true"></i> **Validity Period**|1 year|Standard test certificate lifetime|  

**Expected Results**:

|Aspect|Value|  
|---|---|  
|<i class="fal fa-traffic-light" aria-hidden="true"></i> **State**|⚠️ **WARNING**|  
|<i class="fal fa-magnifying-glass" aria-hidden="true"></i> **Detection**|2 certificates with identical Subject/SAN detected|  
|<i class="fal fa-bell" aria-hidden="true"></i> **Alert Message**|"Duplicate Certificate Detected - Subject: CN=duplicate.test.com"|  
|<i class="fal fa-circle-info" aria-hidden="true"></i> **Details**|Shows count: "2 certificates with identical Subject/SAN"|  
|<i class="fal fa-fingerprint" aria-hidden="true"></i> **Thumbprints**|Lists both certificate thumbprints for identification|  
|<i class="fal fa-lightbulb" aria-hidden="true"></i> **Recommendation**|Remove old certificate after renewal verification|  

### <i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Scenario 2: High-Risk Duplicates (Multiple Private Keys)

**Purpose**: Validate ERROR state when multiple certificates with identical Subject/SAN all have private keys.

**Configuration**:

|Setting|Value|Rationale|  
|---|---|---|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Certificate Type**|Self-signed (test certificates)|Creates controlled high-risk scenario|  
|<i class="fal fa-tag" aria-hidden="true"></i> **Subject**|`CN=privatekey.test.com`|Identical Subject for both certificates|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> **Store Location**|`Cert:\LocalMachine\My`|Same store for both certificates|  
|<i class="fal fa-hashtag" aria-hidden="true"></i> **Certificate Count**|2 certificates|Both have private keys|  
|<i class="fal fa-key" aria-hidden="true"></i> **Private Keys**|**YES** for both certificates|HIGH RISK: Application selection ambiguity|  
|<i class="fal fa-calendar-day" aria-hidden="true"></i> **Validity Period**|1 year|Standard test certificate lifetime|  

**Expected Results**:

|Aspect|Value|  
|---|---|  
|<i class="fal fa-traffic-light" aria-hidden="true"></i> **State**|❌ **ERROR**|  
|<i class="fal fa-gauge-high" aria-hidden="true"></i> **Risk Level**|**HIGH RISK**|  
|<i class="fal fa-magnifying-glass" aria-hidden="true"></i> **Detection**|Multiple certificates with identical Subject/SAN all have private keys|  
|<i class="fal fa-bell" aria-hidden="true"></i> **Alert Message**|"High-Risk Duplicate Certificate - Multiple private keys detected"|  
|<i class="fal fa-burst" aria-hidden="true"></i> **Impact**|Applications may select wrong certificate with unpredictable results|  
|<i class="fal fa-lightbulb" aria-hidden="true"></i> **Recommendation**|Remove old certificate immediately|  

### <i class="fal fa-network-wired" aria-hidden="true"></i> Scenario 3: Cross-Store Duplicates

**Purpose**: Validate detection of certificates duplicated across LocalMachine and CurrentUser stores.

**Configuration**:

|Setting|Value|Rationale|  
|---|---|---|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Certificate Type**|Self-signed (test certificate)|Creates controlled cross-store scenario|  
|<i class="fal fa-tag" aria-hidden="true"></i> **Subject**|`CN=crossstore.test.com`|Identifies cross-store test|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> **Store Locations**|`Cert:\LocalMachine\My` AND `Cert:\CurrentUser\My`|Same certificate in both stores|  
|<i class="fal fa-copy" aria-hidden="true"></i> **Duplication Method**|Export from LocalMachine, import to CurrentUser|Simulates accidental duplication|  
|<i class="fal fa-fingerprint" aria-hidden="true"></i> **Thumbprint**|Identical in both stores|Same certificate, different locations|  

**Expected Results**:

|Aspect|Value|  
|---|---|  
|<i class="fal fa-traffic-light" aria-hidden="true"></i> **State**|⚠️ **WARNING**|  
|<i class="fal fa-magnifying-glass" aria-hidden="true"></i> **Detection**|Certificate exists in multiple stores|  
|<i class="fal fa-bell" aria-hidden="true"></i> **Alert Message**|"Cross-Store Duplicate Detected - Certificate exists in multiple stores"|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> **Store Details**|Shows both `Cert:\LocalMachine\My` and `Cert:\CurrentUser\My`|  
|<i class="fal fa-lightbulb" aria-hidden="true"></i> **Recommendation**|Remove from unnecessary stores (consolidate to single store)|  

### <i class="fal fa-check" aria-hidden="true"></i> Scenario 4: Renewal Success (Single Valid Certificate)

**Purpose**: Validate OK state when old certificate is properly removed after renewal.

**Configuration**:

|Setting|Value|Rationale|  
|---|---|---|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Certificate Type**|Self-signed (test certificates)|Simulates renewal workflow|  
|<i class="fal fa-tag" aria-hidden="true"></i> **Subject**|`CN=renewal.test.com`|Identifies renewal test scenario|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> **Store Location**|`Cert:\LocalMachine\My`|Standard certificate store|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Original Certificate**|Expires in 30 days|Old certificate nearing expiration|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Renewed Certificate**|Expires in 1 year|New certificate with extended validity|  
|<i class="fal fa-broom" aria-hidden="true"></i> **Cleanup Action**|**Remove old certificate after renewal**|Proper cleanup prevents duplicates|  

**Expected Results**:

|Aspect|Value|  
|---|---|  
|<i class="fal fa-traffic-light" aria-hidden="true"></i> **State**|✅ **OK**|  
|<i class="fal fa-magnifying-glass" aria-hidden="true"></i> **Detection**|Single certificate remains after cleanup|  
|<i class="fal fa-hashtag" aria-hidden="true"></i> **Duplicate Count**|0 (no duplicates)|  
|<i class="fal fa-lightbulb" aria-hidden="true"></i> **Recommendation**|No action needed (proper certificate management)|  

### <i class="fal fa-circle-info" aria-hidden="true"></i> Scenario 5: Allowed Duplicates (Within Threshold)

**Purpose**: Validate threshold configuration - duplicates within acceptable limit.

**Configuration**:

|Setting|Value|Rationale|  
|---|---|---|  
|<i class="fal fa-file-certificate" aria-hidden="true"></i> **Certificate Type**|Self-signed (test certificates)|Creates controlled threshold test|  
|<i class="fal fa-tag" aria-hidden="true"></i> **Subject**|`CN=threshold.test.com`|Identifies threshold test scenario|  
|<i class="fal fa-box-archive" aria-hidden="true"></i> **Store Location**|`Cert:\LocalMachine\My`|Standard certificate store|  
|<i class="fal fa-hashtag" aria-hidden="true"></i> **Certificate Count**|2 certificates|Tests threshold enforcement|  
|<i class="fal fa-arrow-up-wide-short" aria-hidden="true"></i> **MaxAllowedDuplicates**|Configurable (1 or 2)|Determines alert behavior|  

**Expected Results**:

|Configuration|State|Explanation|  
|---|---|---|  
|**MaxAllowedDuplicates = 2, Count = 2**|✅ **OK**|At threshold (no alert)|  
|**MaxAllowedDuplicates = 1, Count = 2**|⚠️ **WARNING**|Exceeds threshold (alert triggered)|  

## <i class="fal fa-tools" aria-hidden="true"></i> Batch Duplicate Certificate Testing Script

**Purpose**: Create all 5 test scenarios with a single PowerShell script.

```powershell
# Nodinite Duplicate Certificate Detection Testing Suite
# Tests duplicate detection across same store, cross-store, and private key scenarios
# Requires: PowerShell 7+, Administrator privileges
# Usage: .\Test-DuplicateDetection.ps1

Write-Host "=== Nodinite Duplicate Certificate Detection Testing Suite ===" -ForegroundColor Magenta
Write-Host "Creating comprehensive duplicate certificate test scenarios..." -ForegroundColor Cyan
if ($PSVersionTable.PSVersion.Major -ge 7) {
    Write-Host "Note: Running in PowerShell $($PSVersionTable.PSVersion.Major). Some certificate operations work best in Windows PowerShell 5.1" -ForegroundColor Yellow
}

$testCertificates = @()
$testErrors = @()

try {
    Write-Host "`n:fa-info-circle: Creating duplicate certificate test scenarios" -ForegroundColor Blue
    
    # Scenario 1: Same Store Duplicates
    Write-Host "`n[Scenario 1/5] Creating duplicates in LocalMachine\My store..." -ForegroundColor Green
    try {
        $dup1 = New-SelfSignedCertificate `
            -Subject "CN=duplicate.test.com" `
            -DnsName "duplicate.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Duplicate Test - Original" `
            -ErrorAction Stop
        
        $dup2 = New-SelfSignedCertificate `
            -Subject "CN=duplicate.test.com" `
            -DnsName "duplicate.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Duplicate Test - Renewal" `
            -ErrorAction Stop
        
        $testCertificates += @{ Scenario = "Same Store"; Subject = "CN=duplicate.test.com"; Count = 2; Store = "LocalMachine\My"; Thumbprints = @($dup1.Thumbprint, $dup2.Thumbprint) }
        Write-Host ":fa-check: Created 2 duplicate certificates in LocalMachine\My" -ForegroundColor Green
        Write-Host "  • Thumbprint 1: $($dup1.Thumbprint.Substring(0,16))..." -ForegroundColor White
        Write-Host "  • Thumbprint 2: $($dup2.Thumbprint.Substring(0,16))..." -ForegroundColor White
    }
    catch {
        $testErrors += "Scenario 1 (Same Store Duplicates): $_"
        Write-Host ":fa-times-circle: Failed to create same-store duplicates: $_" -ForegroundColor Red
    }
    
    # Scenario 2: High-Risk Private Key Duplicates
    Write-Host "`n[Scenario 2/5] Creating high-risk duplicates with private keys..." -ForegroundColor Green
    try {
        $privkey1 = New-SelfSignedCertificate `
            -Subject "CN=privatekey.test.com" `
            -DnsName "privatekey.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Private Key Risk - Original" `
            -ErrorAction Stop
        
        $privkey2 = New-SelfSignedCertificate `
            -Subject "CN=privatekey.test.com" `
            -DnsName "privatekey.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Private Key Risk - Duplicate" `
            -ErrorAction Stop
        
        # Verify both have private keys
        $key1_has = $privkey1.HasPrivateKey
        $key2_has = $privkey2.HasPrivateKey
        
        $testCertificates += @{ Scenario = "High-Risk Private Keys"; Subject = "CN=privatekey.test.com"; Count = 2; PrivateKeys = @($key1_has, $key2_has); RiskLevel = "HIGH" }
        Write-Host ":fa-check: Created 2 high-risk duplicate certificates with private keys" -ForegroundColor Green
        Write-Host "  • Certificate 1 has private key: $key1_has" -ForegroundColor White
        Write-Host "  • Certificate 2 has private key: $key2_has" -ForegroundColor White
        Write-Host "  • Expected Alert: ERROR - High-Risk Duplicate (multiple private keys)" -ForegroundColor Yellow
    }
    catch {
        $testErrors += "Scenario 2 (Private Key Duplicates): $_"
        Write-Host ":fa-times-circle: Failed to create private key duplicates: $_" -ForegroundColor Red
    }
    
    # Scenario 3: Cross-Store Duplicates
    Write-Host "`n[Scenario 3/5] Creating cross-store duplicates..." -ForegroundColor Green
    try {
        # Create in LocalMachine
        $crossstore1 = New-SelfSignedCertificate `
            -Subject "CN=crossstore.test.com" `
            -DnsName "crossstore.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Cross-Store - Machine Store" `
            -ErrorAction Stop
        
        # Export for import to CurrentUser
        $exportPath = "C:\temp\crossstore-cert-$([Guid]::NewGuid().ToString().Substring(0,8)).cer"
        Export-Certificate -Cert $crossstore1 -FilePath $exportPath -Force -ErrorAction Stop | Out-Null
        
        # Import to CurrentUser
        Import-Certificate -FilePath $exportPath -CertStoreLocation Cert:\CurrentUser\My -ErrorAction Stop | Out-Null
        
        $testCertificates += @{ Scenario = "Cross-Store"; Subject = "CN=crossstore.test.com"; Stores = @("Cert:\LocalMachine\My", "Cert:\CurrentUser\My"); ExportPath = $exportPath }
        Write-Host ":fa-check: Created cross-store duplicate certificate" -ForegroundColor Green
        Write-Host "  • LocalMachine\My: $($crossstore1.Thumbprint.Substring(0,16))..." -ForegroundColor White
        Write-Host "  • CurrentUser\My: [Same thumbprint, different store]" -ForegroundColor White
    }
    catch {
        $testErrors += "Scenario 3 (Cross-Store Duplicates): $_"
        Write-Host ":fa-times-circle: Failed to create cross-store duplicates: $_" -ForegroundColor Red
    }
    
    # Scenario 4: Threshold Test (3 duplicates)
    Write-Host "`n[Scenario 4/5] Creating multiple duplicates to test threshold..." -ForegroundColor Green
    try {
        $threshold1 = New-SelfSignedCertificate `
            -Subject "CN=threshold.test.com" `
            -DnsName "threshold.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Threshold Test - Cert 1" `
            -ErrorAction Stop
        
        $threshold2 = New-SelfSignedCertificate `
            -Subject "CN=threshold.test.com" `
            -DnsName "threshold.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Threshold Test - Cert 2" `
            -ErrorAction Stop
        
        $threshold3 = New-SelfSignedCertificate `
            -Subject "CN=threshold.test.com" `
            -DnsName "threshold.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Threshold Test - Cert 3" `
            -ErrorAction Stop
        
        $testCertificates += @{ Scenario = "Threshold Test"; Subject = "CN=threshold.test.com"; Count = 3; ExpectedAlert = "If MaxAllowedDuplicates < 3" }
        Write-Host ":fa-check: Created 3 duplicate certificates to test threshold" -ForegroundColor Green
        Write-Host "  • Alert if MaxAllowedDuplicates = 1 or 2" -ForegroundColor White
        Write-Host "  • No alert if MaxAllowedDuplicates >= 3" -ForegroundColor White
    }
    catch {
        $testErrors += "Scenario 4 (Threshold Test): $_"
        Write-Host ":fa-times-circle: Failed to create threshold test certificates: $_" -ForegroundColor Red
    }
    
    # Scenario 5: Renewal Success (No Duplicates)
    Write-Host "`n[Scenario 5/5] Creating proper renewal (no duplicates)..." -ForegroundColor Green
    try {
        $original = New-SelfSignedCertificate `
            -Subject "CN=renewal.test.com" `
            -DnsName "renewal.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddDays(30) `
            -FriendlyName "Renewal Test - Original (Expiring)" `
            -ErrorAction Stop
        
        $renewed = New-SelfSignedCertificate `
            -Subject "CN=renewal.test.com" `
            -DnsName "renewal.test.com" `
            -CertStoreLocation Cert:\LocalMachine\My `
            -NotAfter (Get-Date).AddYears(1) `
            -FriendlyName "Renewal Test - New" `
            -ErrorAction Stop
        
        # Remove old certificate (proper cleanup)
        Remove-Item "Cert:\LocalMachine\My\$($original.Thumbprint)" -Force -ErrorAction Stop
        
        $testCertificates += @{ Scenario = "Proper Renewal"; Subject = "CN=renewal.test.com"; Status = "Old removed"; Remaining = $renewed.Thumbprint }
        Write-Host ":fa-check: Created and cleaned up renewal (old cert removed)" -ForegroundColor Green
        Write-Host "  • Old Certificate: $($original.Thumbprint.Substring(0,16))... [REMOVED]" -ForegroundColor White
        Write-Host "  • New Certificate: $($renewed.Thumbprint.Substring(0,16))... [KEPT]" -ForegroundColor White
        Write-Host "  • Expected Alert: NONE (proper cleanup)" -ForegroundColor Green
    }
    catch {
        $testErrors += "Scenario 5 (Proper Renewal): $_"
        Write-Host ":fa-times-circle: Failed to create proper renewal test: $_" -ForegroundColor Red
    }
}
catch {
    Write-Host ":fa-times-circle: Unexpected error during test setup: $_" -ForegroundColor Red
}

# Summary Report
Write-Host "`n" -ForegroundColor White
Write-Host "=== Test Scenario Summary ===" -ForegroundColor Cyan
Write-Host ":fa-info-circle: Test Scenarios Created: $($testCertificates.Count)/5" -ForegroundColor Blue

if ($testCertificates.Count -gt 0) {
    Write-Host "`nScenarios:" -ForegroundColor Green
    foreach ($scenario in $testCertificates) {
        Write-Host "  • $($scenario.Scenario) - Subject: $($scenario.Subject)" -ForegroundColor White
    }
}

if ($testErrors.Count -gt 0) {
    Write-Host "`n:fa-triangle-exclamation: Errors Encountered:" -ForegroundColor Yellow
    foreach ($error in $testErrors) {
        Write-Host "  • $error" -ForegroundColor Yellow
    }
}

Write-Host "`n:fa-info-circle: Configuration:" -ForegroundColor Blue
Write-Host "  • Enable in Settings: Administration → Certificate Monitoring → Duplicates tab" -ForegroundColor White
Write-Host "  • Set DetectDuplicateCertificates = true" -ForegroundColor White
Write-Host "  • Enable AlertOnDuplicatesWithPrivateKey for high-risk detection" -ForegroundColor White
Write-Host "  • Set MaxAllowedDuplicates = 1 (strict) or 2 (renewal in progress)" -ForegroundColor White
Write-Host "  • Restart monitoring service" -ForegroundColor White
Write-Host "  • Verify duplicate alerts appear in Certificate View" -ForegroundColor White

Write-Host "\n:fa-check: Test setup complete! Duplicate detection scenarios ready for validation." -ForegroundColor Green
```

## <i class="fal fa-broom" aria-hidden="true"></i> Cleanup Script

Remove all test certificates after validation:

```powershell
# Cleanup Nodinite Duplicate Certificate Test Certificates

Write-Host "=== Cleanup: Duplicate Certificate Test Certificates ===" -ForegroundColor Magenta
Write-Host "Removing all test duplicate certificates..." -ForegroundColor Cyan

$testSubjects = @(
    "CN=duplicate.test.com",
    "CN=privatekey.test.com",
    "CN=crossstore.test.com",
    "CN=threshold.test.com",
    "CN=renewal.test.com"
)

$removedCount = 0
$cleanupErrors = @()

# Remove from LocalMachine store
Write-Host "`n:fa-globe: Removing certificates from LocalMachine\My..." -ForegroundColor Blue
foreach ($subject in $testSubjects) {
    try {
        $certs = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -eq $subject }  
        foreach ($cert in $certs) {
            Remove-Item "Cert:\LocalMachine\My\$($cert.Thumbprint)" -Force -ErrorAction Stop
            Write-Host ":fa-check: Removed $($cert.FriendlyName) (Thumbprint: $($cert.Thumbprint.Substring(0,8))...)" -ForegroundColor Green
            $removedCount++
        }
    }
    catch {
        $cleanupErrors += "Failed to remove subject '$subject' from LocalMachine: $_"
        Write-Host ":fa-times-circle: Failed to remove subject '$subject': $_" -ForegroundColor Red
    }
}

# Remove from CurrentUser store
Write-Host "`n:fa-user: Removing certificates from CurrentUser\My..." -ForegroundColor Blue
foreach ($subject in $testSubjects) {
    try {
        $certs = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Subject -eq $subject }  
        foreach ($cert in $certs) {
            Remove-Item "Cert:\CurrentUser\My\$($cert.Thumbprint)" -Force -ErrorAction Stop
            Write-Host ":fa-check: Removed $($cert.FriendlyName) from CurrentUser\My" -ForegroundColor Green
            $removedCount++
        }
    }
    catch {
        $cleanupErrors += "Failed to remove subject '$subject' from CurrentUser: $_"
        Write-Host ":fa-triangle-exclamation: Failed to remove from CurrentUser: $_" -ForegroundColor Yellow
    }
}

# Cleanup temporary export files
Write-Host "`n:fa-folder: Removing temporary export files..." -ForegroundColor Blue
try {
    $tempFiles = Get-ChildItem "C:\temp\crossstore-cert-*.cer" -ErrorAction SilentlyContinue
    foreach ($file in $tempFiles) {
        Remove-Item $file.FullName -Force -ErrorAction Stop
        Write-Host ":fa-check: Removed temporary file: $($file.Name)" -ForegroundColor Green
    }
}
catch {
    Write-Host ":fa-triangle-exclamation: Note: Some temporary files may not exist" -ForegroundColor Yellow
}

# Cleanup Summary
Write-Host "`n=== Cleanup Summary ===" -ForegroundColor Cyan
Write-Host ":fa-check: Test Certificates Removed: $removedCount" -ForegroundColor Green

if ($cleanupErrors.Count -gt 0) {
    Write-Host "`n:fa-triangle-exclamation: Errors During Cleanup:" -ForegroundColor Yellow
    foreach ($error in $cleanupErrors) {
        Write-Host "  • $error" -ForegroundColor Yellow
    }
    Write-Host "`nNote: Some certificates may have already been removed. Review above for any critical errors." -ForegroundColor Yellow
}

Write-Host "\n:fa-check: Cleanup complete! Test certificates removed." -ForegroundColor Green
```

## <i class="fal fa-question-circle" aria-hidden="true"></i> Frequently Asked Questions

### Q1: Why is cross-store duplication considered a WARNING instead of just informational?

**A:** Cross-store duplication typically indicates misconfiguration or accidental backup/restore operations. When the same certificate exists in both `Cert:\LocalMachine\My` and `Cert:\CurrentUser\My`, it creates management overhead and potential confusion during renewals. Applications and services may look in different stores, leading to inconsistent behavior. WARNING severity ensures administrators are notified to consolidate certificates to the appropriate single store.

### Q2: What happens if I have multiple certificates with private keys for the same Subject/SAN?

**A:** This is a **HIGH RISK** scenario (ERROR state) because applications may select the wrong certificate unpredictably. For example, [IIS][] rebinds HTTPS connections during application pool recycles and selects certificates by Subject/SAN match, not by expiration date. If multiple certificates with private keys exist, IIS might choose an expired certificate, causing production outages. Always remove old certificates with private keys immediately after renewal verification.

### Q3: How do I configure the duplicate certificate threshold?

**A:** Navigate to **Administration → Settings → [Certificate Monitoring][Certificate Monitoring Overview] → Duplicates** tab and configure:

* **DetectDuplicateCertificates** = `true` (enables detection)
* **MaxAllowedDuplicates** = `1` (strict - alerts on any duplicate) or `2` (tolerates renewal overlap)
* **AlertOnDuplicatesWithPrivateKey** = `true` (enables high-risk ERROR alerts)
* **TreatDuplicatesAsError** = `false` (WARNING) or `true` (ERROR for all duplicates)

Restart the monitoring service after configuration changes. Set `MaxAllowedDuplicates = 2` during planned renewal windows to avoid false alerts.

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-shield-halved" aria-hidden="true"></i> [Certificate Monitoring Overview][Certificate Monitoring Overview]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-certificate" aria-hidden="true"></i> [FAQ: IIS Binding and SAN Monitoring][]  
* <i class="fal fa-bug" aria-hidden="true"></i> [Troubleshooting - Overview][Certificate Troubleshooting]  
* <i class="fal fa-cog" aria-hidden="true"></i> [Certificate Configuration][Certificate Configuration]  

[Certificate Configuration]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/certificates/configuration/
[Certificate Monitoring Overview]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/certificates/overview/
[Certificate Troubleshooting]:https://docs.nodinite.com/logging-and-monitoring/windows-server/troubleshooting/overview/
[Duplicate Certificate Detection]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/certificates/duplicate-certificate-detection/
[Expected State]:https://docs.nodinite.com/administration/monitor-management/resources/features/expected-state/
[FAQ: IIS Binding and SAN Monitoring]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/certificates/troubleshooting/faq-iis-binding-and-san-monitoring/
[IIS]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/iis/