Skip to content
Documentation
Updated 12 minutes to read
Markdown

Validate Private Key Health Monitoring with automated PowerShell test scripts covering all detection scenarios - from missing private keys and exportable keys to weak key lengths and healthy configurations.

What's on This Page:

Why Test Private Key Health Monitoring?

Private key health testing validates that monitoring correctly identifies:

  • ❌ Missing private keys (ERROR) - Certificate exists but private key inaccessible
  • ⚠️ Exportable private keys (WARNING) - Security risk from keys that can be exported
  • ⚠️ Weak key lengths (WARNING) - RSA < 2048 bits or ECDSA < 256 bits
  • ✅ Healthy certificates (OK) - Non-exportable keys with sufficient length

Related Documentation: See Private Key Health for complete feature documentation and security best practices.

Create comprehensive test certificates to validate all aspects of certificate monitoring and private key health detection:

Scenario Test Case Expected State Description
1. Missing Private Key Certificate without accessible private key ❌ Error Tests detection when certificate exists but private key is missing or inaccessible
2. Exportable Private Key Certificate with exportable private key ⚠️ Warning Tests security risk detection for private keys that can be exported
3. Weak Cryptography 1024-bit RSA certificate ⚠️ Warning Tests detection of cryptographically weak key lengths
4. Healthy Certificate 2048-bit non-exportable RSA ✅ OK Tests baseline monitoring for properly configured certificates
5. ECDSA Certificate ECDSA P-256 non-exportable ✅ OK Tests modern elliptic curve cryptography support
  • Individual Testing: Jump to specific scenarios using the links above
  • Comprehensive Testing: Use the Batch Testing Script to create all scenarios at once
  • Validation Guide: Follow Usage Instructions for monitoring verification steps

Testing Scenario 1: Certificate Without Private Key

Section titled “ Testing Scenario 1: Certificate Without Private Key”

Use Case: Test monitoring detection of certificates where the private key is missing or inaccessible.

Terminal window
# Create certificate with private key, then export/import to remove private key access
Write-Host "Creating certificate without accessible private key..." -ForegroundColor Cyan
# Step 1: Create certificate with private key
$cert = New-SelfSignedCertificate `
-Subject "CN=TestCert-NoPrivateKey, O=Nodinite Testing" `
-CertStoreLocation "Cert:\LocalMachine\My" `
-KeyLength 2048 `
-KeyAlgorithm RSA `
-HashAlgorithm SHA256 `
-NotAfter (Get-Date).AddDays(90) `
-KeyUsage DigitalSignature, KeyEncipherment
Write-Host "✓ Certificate created with thumbprint: $($cert.Thumbprint)" -ForegroundColor Green
# Step 2: Export certificate without private key
$exportPath = "$env:TEMP\TestCert-NoPrivateKey.cer"
Export-Certificate -Cert $cert -FilePath $exportPath -Type CERT
Write-Host "✓ Certificate exported to: $exportPath" -ForegroundColor Green
# Step 3: Remove original certificate (with private key)
Remove-Item -Path "Cert:\LocalMachine\My\$($cert.Thumbprint)" -Force
Write-Host "✓ Original certificate with private key removed" -ForegroundColor Yellow
# Step 4: Import certificate back (without private key)
$importedCert = Import-Certificate -FilePath $exportPath -CertStoreLocation "Cert:\LocalMachine\My"
Write-Host "✓ Certificate re-imported without private key access" -ForegroundColor Green
Write-Host " Thumbprint: $($importedCert.Thumbprint)" -ForegroundColor White
# Verification
$testCert = Get-Item -Path "Cert:\LocalMachine\My\$($importedCert.Thumbprint)"
if ($testCert.HasPrivateKey) {
Write-Host "⚠️ Certificate shows HasPrivateKey=True but private key may not be accessible" -ForegroundColor Yellow
} else {
Write-Host "✓ Certificate HasPrivateKey=False - monitoring should detect missing private key" -ForegroundColor Green
}
# Cleanup instruction
Write-Host "`n:fa-broom: Cleanup Command:" -ForegroundColor Magenta
Write-Host "Remove-Item 'Cert:\LocalMachine\My\$($importedCert.Thumbprint)' -Force" -ForegroundColor White
  • State: ❌ Error
  • Detection: Certificate exists but private key is missing or inaccessible
  • Alert: Private key health check failure

Testing Scenario 2: Exportable Private Key

Section titled “ Testing Scenario 2: Exportable Private Key”

Use Case: Test monitoring detection of certificates with exportable private keys (security risk).

Terminal window
# Create certificate with exportable private key
Write-Host "Creating certificate with exportable private key..." -ForegroundColor Cyan
$cert = New-SelfSignedCertificate `
-Subject "CN=TestCert-ExportableKey, O=Nodinite Testing" `
-CertStoreLocation "Cert:\LocalMachine\My" `
-KeyLength 2048 `
-KeyAlgorithm RSA `
-HashAlgorithm SHA256 `
-KeyExportPolicy Exportable `
-NotAfter (Get-Date).AddDays(90) `
-KeyUsage DigitalSignature, KeyEncipherment
Write-Host "✓ Certificate created with exportable private key" -ForegroundColor Green
Write-Host " Thumbprint: $($cert.Thumbprint)" -ForegroundColor White
Write-Host " Subject: $($cert.Subject)" -ForegroundColor White
# Verification - Test if private key is actually exportable
try {
$exportPath = "$env:TEMP\TestExportableKey.pfx"
$password = ConvertTo-SecureString -String "TestPassword123!" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath $exportPath -Password $password -Force | Out-Null
Write-Host "✓ Private key export successful - key is exportable" -ForegroundColor Yellow
Remove-Item $exportPath -Force -ErrorAction SilentlyContinue
} catch {
Write-Host "✗ Private key export failed: $($_.Exception.Message)" -ForegroundColor Red
}
# Display certificate properties
$certDetails = Get-Item -Path "Cert:\LocalMachine\My\$($cert.Thumbprint)"
Write-Host "`n:fa-info-circle: Certificate Properties:" -ForegroundColor Cyan
Write-Host " HasPrivateKey: $($certDetails.HasPrivateKey)" -ForegroundColor White
Write-Host " KeyAlgorithm: $($certDetails.PublicKey.Key.KeySize)-bit $($certDetails.PublicKey.Oid.FriendlyName)" -ForegroundColor White
# Cleanup instruction
Write-Host "`n:fa-broom: Cleanup Command:" -ForegroundColor Magenta
Write-Host "Remove-Item 'Cert:\LocalMachine\My\$($cert.Thumbprint)' -Force" -ForegroundColor White
  • State: ⚠️ Warning
  • Detection: Private key is exportable (security risk)
  • Alert: Exportable private key detected

Testing Scenario 3: Weak Key Length (1024-bit RSA)

Section titled “ Testing Scenario 3: Weak Key Length (1024-bit RSA)”

Use Case: Test monitoring detection of certificates with weak cryptographic key lengths.

Terminal window
# Create certificate with weak 1024-bit RSA key
Write-Host "Creating certificate with weak 1024-bit RSA key..." -ForegroundColor Cyan
$cert = New-SelfSignedCertificate `
-Subject "CN=TestCert-WeakKey, O=Nodinite Testing" `
-CertStoreLocation "Cert:\LocalMachine\My" `
-KeyLength 1024 `
-KeyAlgorithm RSA `
-HashAlgorithm SHA256 `
-KeyExportPolicy NonExportable `
-NotAfter (Get-Date).AddDays(90) `
-KeyUsage DigitalSignature, KeyEncipherment
Write-Host "✓ Certificate created with 1024-bit RSA key (weak)" -ForegroundColor Yellow
Write-Host " Thumbprint: $($cert.Thumbprint)" -ForegroundColor White
Write-Host " Subject: $($cert.Subject)" -ForegroundColor White
# Display key strength details
$certDetails = Get-Item -Path "Cert:\LocalMachine\My\$($cert.Thumbprint)"
Write-Host "`n:fa-shield-halved: Key Strength Analysis:" -ForegroundColor Yellow
Write-Host " Algorithm: $($certDetails.PublicKey.Oid.FriendlyName)" -ForegroundColor White
Write-Host " Key Size: $($certDetails.PublicKey.Key.KeySize) bits" -ForegroundColor Red
Write-Host " Security Level: WEAK (minimum recommended: 2048 bits)" -ForegroundColor Red
Write-Host " Hash Algorithm: $($certDetails.SignatureAlgorithm.FriendlyName)" -ForegroundColor White
# Additional security context
Write-Host "`n:fa-info-circle: Security Context:" -ForegroundColor Cyan
Write-Host " • 1024-bit RSA keys are deprecated by NIST (SP 800-57)" -ForegroundColor White
Write-Host " • Industry standard minimum is 2048-bit RSA" -ForegroundColor White
Write-Host " • This certificate should trigger a security warning" -ForegroundColor White
# Cleanup instruction
Write-Host "`n:fa-broom: Cleanup Command:" -ForegroundColor Magenta
Write-Host "Remove-Item 'Cert:\LocalMachine\My\$($cert.Thumbprint)' -Force" -ForegroundColor White
  • State: ⚠️ Warning or ❌ Error (based on policy)
  • Detection: Key length below security standards (< 2048 bits)
  • Alert: Weak cryptographic key detected

Testing Scenario 4: Healthy Certificate (2048-bit Non-exportable RSA)

Section titled “ Testing Scenario 4: Healthy Certificate (2048-bit Non-exportable RSA)”

Use Case: Test monitoring of a properly configured certificate that should show healthy status.

Terminal window
# Create secure certificate with best practices
Write-Host "Creating healthy certificate with security best practices..." -ForegroundColor Cyan
$cert = New-SelfSignedCertificate `
-Subject "CN=TestCert-Healthy, O=Nodinite Testing" `
-CertStoreLocation "Cert:\LocalMachine\My" `
-KeyLength 2048 `
-KeyAlgorithm RSA `
-HashAlgorithm SHA256 `
-KeyExportPolicy NonExportable `
-NotAfter (Get-Date).AddDays(365) `
-KeyUsage DigitalSignature, KeyEncipherment `
-EnhancedKeyUsage "1.3.6.1.5.5.7.3.1" # Server Authentication
Write-Host "✓ Healthy certificate created successfully" -ForegroundColor Green
Write-Host " Thumbprint: $($cert.Thumbprint)" -ForegroundColor White
Write-Host " Subject: $($cert.Subject)" -ForegroundColor White
# Display security properties
$certDetails = Get-Item -Path "Cert:\LocalMachine\My\$($cert.Thumbprint)"
Write-Host "`n:fa-shield-check: Security Properties:" -ForegroundColor Green
Write-Host " Algorithm: $($certDetails.PublicKey.Oid.FriendlyName)" -ForegroundColor White
Write-Host " Key Size: $($certDetails.PublicKey.Key.KeySize) bits (Strong)" -ForegroundColor Green
Write-Host " Hash Algorithm: $($certDetails.SignatureAlgorithm.FriendlyName)" -ForegroundColor White
Write-Host " Private Key: $($certDetails.HasPrivateKey) (Non-exportable)" -ForegroundColor Green
Write-Host " Valid Until: $($certDetails.NotAfter.ToString('yyyy-MM-dd'))" -ForegroundColor White
# Test private key accessibility
try {
$privateKey = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($certDetails)
if ($privateKey) {
Write-Host " Private Key Access: ✓ Available and accessible" -ForegroundColor Green
}
} catch {
Write-Host " Private Key Access: ✗ Error accessing private key" -ForegroundColor Red
}
# Calculate days until expiration
$daysUntilExpiry = ($certDetails.NotAfter - (Get-Date)).Days
Write-Host "`n:fa-calendar-check: Expiration Status:" -ForegroundColor Cyan
Write-Host " Days Until Expiry: $daysUntilExpiry days" -ForegroundColor White
if ($daysUntilExpiry -gt 90) {
Write-Host " Status: ✓ Well within expiration threshold" -ForegroundColor Green
} elseif ($daysUntilExpiry -gt 30) {
Write-Host " Status: ⚠️ Approaching expiration (< 90 days)" -ForegroundColor Yellow
} else {
Write-Host " Status: ⚠️ Critical - Expires soon (< 30 days)" -ForegroundColor Red
}
# Cleanup instruction
Write-Host "`n:fa-broom: Cleanup Command:" -ForegroundColor Magenta
Write-Host "Remove-Item 'Cert:\LocalMachine\My\$($cert.Thumbprint)' -Force" -ForegroundColor White
  • State: ✅ OK
  • Detection: Strong key, non-exportable, valid, not expiring soon
  • Alert: No alerts (healthy certificate)

Testing Scenario 5: ECDSA Certificate with Strong Key

Section titled “ Testing Scenario 5: ECDSA Certificate with Strong Key”

Use Case: Test monitoring of modern elliptic curve cryptography (ECDSA) certificates.

Terminal window
# Create ECDSA certificate with P-256 curve (256-bit equivalent)
Write-Host "Creating ECDSA certificate with strong key..." -ForegroundColor Cyan
$cert = New-SelfSignedCertificate `
-Subject "CN=TestCert-ECDSA, O=Nodinite Testing" `
-CertStoreLocation "Cert:\LocalMachine\My" `
-KeyAlgorithm ECDSA_nistP256 `
-KeyExportPolicy NonExportable `
-HashAlgorithm SHA256 `
-NotAfter (Get-Date).AddDays(365) `
-KeyUsage DigitalSignature, KeyEncipherment
Write-Host "✓ ECDSA certificate created successfully" -ForegroundColor Green
Write-Host " Thumbprint: $($cert.Thumbprint)" -ForegroundColor White
Write-Host " Subject: $($cert.Subject)" -ForegroundColor White
# Display ECDSA-specific properties
$certDetails = Get-Item -Path "Cert:\LocalMachine\My\$($cert.Thumbprint)"
Write-Host "`n:fa-shield-check: ECDSA Properties:" -ForegroundColor Green
Write-Host " Algorithm: $($certDetails.PublicKey.Oid.FriendlyName)" -ForegroundColor White
Write-Host " Curve: P-256 (256-bit, equivalent to RSA 3072-bit)" -ForegroundColor Green
Write-Host " Hash Algorithm: $($certDetails.SignatureAlgorithm.FriendlyName)" -ForegroundColor White
Write-Host " Private Key: $($certDetails.HasPrivateKey) (Non-exportable)" -ForegroundColor Green
Write-Host "`n:fa-info-circle: ECDSA Advantages:" -ForegroundColor Cyan
Write-Host " • Smaller key size with equivalent security to larger RSA keys" -ForegroundColor White
Write-Host " • Faster cryptographic operations" -ForegroundColor White
Write-Host " • Lower computational overhead" -ForegroundColor White
Write-Host " • Increasingly common in modern TLS implementations" -ForegroundColor White
# Cleanup instruction
Write-Host "`n:fa-broom: Cleanup Command:" -ForegroundColor Magenta
Write-Host "Remove-Item 'Cert:\LocalMachine\My\$($cert.Thumbprint)' -Force" -ForegroundColor White
  • State: ✅ OK
  • Detection: Strong ECDSA key (P-256 curve), non-exportable, valid
  • Alert: No alerts (modern cryptography properly configured)

Create all five test scenarios at once:

Terminal window
# Nodinite Certificate Testing Suite
Write-Host "=== Nodinite Certificate Testing Suite ===" -ForegroundColor Magenta
Write-Host "Creating all four certificate testing scenarios..." -ForegroundColor Cyan
$certificates = @()
try {
# Scenario 1: Certificate without private key
Write-Host "`n1. Creating certificate without private key..." -ForegroundColor Yellow
$cert1 = New-SelfSignedCertificate -Subject "CN=Test-NoPrivateKey" -CertStoreLocation "Cert:\LocalMachine\My" -KeyLength 2048
$exportPath = "$env:TEMP\TestCert-NoPrivateKey.cer"
Export-Certificate -Cert $cert1 -FilePath $exportPath -Type CERT | Out-Null
Remove-Item -Path "Cert:\LocalMachine\My\$($cert1.Thumbprint)" -Force
$cert1Import = Import-Certificate -FilePath $exportPath -CertStoreLocation "Cert:\LocalMachine\My"
$certificates += @{Name="No Private Key"; Thumbprint=$cert1Import.Thumbprint; Expected="Error"}
Remove-Item $exportPath -Force
# Scenario 2: Exportable private key
Write-Host "2. Creating certificate with exportable private key..." -ForegroundColor Yellow
$cert2 = New-SelfSignedCertificate -Subject "CN=Test-ExportableKey" -CertStoreLocation "Cert:\LocalMachine\My" -KeyLength 2048 -KeyExportPolicy Exportable
$certificates += @{Name="Exportable Key"; Thumbprint=$cert2.Thumbprint; Expected="Warning"}
# Scenario 3: Weak key length
Write-Host "3. Creating certificate with weak 1024-bit key..." -ForegroundColor Yellow
$cert3 = New-SelfSignedCertificate -Subject "CN=Test-WeakKey" -CertStoreLocation "Cert:\LocalMachine\My" -KeyLength 1024 -KeyExportPolicy NonExportable
$certificates += @{Name="Weak Key (1024-bit)"; Thumbprint=$cert3.Thumbprint; Expected="Warning/Error"}
# Scenario 4: Healthy certificate
Write-Host "4. Creating healthy certificate..." -ForegroundColor Yellow
$cert4 = New-SelfSignedCertificate -Subject "CN=Test-Healthy" -CertStoreLocation "Cert:\LocalMachine\My" -KeyLength 2048 -KeyExportPolicy NonExportable -NotAfter (Get-Date).AddDays(365)
$certificates += @{Name="Healthy Certificate"; Thumbprint=$cert4.Thumbprint; Expected="OK"}
# Summary
Write-Host "`n=== Test Certificate Summary ===" -ForegroundColor Magenta
foreach ($cert in $certificates) {
Write-Host "$($cert.Name): $($cert.Thumbprint) (Expected: $($cert.Expected))" -ForegroundColor White
}
Write-Host "`n:fa-rocket: Next Steps:" -ForegroundColor Cyan
Write-Host "1. Configure Nodinite to monitor LocalMachine\My certificate store" -ForegroundColor White
Write-Host "2. Wait for monitoring agent to discover certificates" -ForegroundColor White
Write-Host "3. Verify each certificate shows expected monitoring state" -ForegroundColor White
Write-Host "4. Test alert notifications for Warning/Error states" -ForegroundColor White
# Cleanup script
Write-Host "`n:fa-broom: Cleanup All Test Certificates:" -ForegroundColor Magenta
foreach ($cert in $certificates) {
Write-Host "Remove-Item 'Cert:\LocalMachine\My\$($cert.Thumbprint)' -Force" -ForegroundColor Gray
}
} catch {
Write-Host "Error creating test certificates: $($_.Exception.Message)" -ForegroundColor Red
}

  1. Open PowerShell 7 as Administrator

    Terminal window
    # Ensure you're using PowerShell 7 and run as Administrator
    # Required for LocalMachine certificate store access
    Start-Process pwsh -Verb RunAs
    # Verify PowerShell version
    $PSVersionTable.PSVersion # Should show 7.x.x or higher
  2. Run Individual Scenarios

    • Copy and paste each scenario script
    • Monitor the certificate in Nodinite interface
    • Verify expected monitoring state
  3. Run Complete Test Suite

    • Use the batch script to create all scenarios
    • Monitor all certificates simultaneously
    • Compare actual vs expected results

After creating test certificates:

  1. Agent Discovery: Wait 1-2 minutes for monitoring agent to discover new certificates
  2. Monitor Views: Check certificate resources appear in Monitor Views
  3. State Verification: Confirm each certificate shows expected state (OK/Warning/Error)
  4. Alert Testing: Verify Warning/Error certificates trigger notifications

Always clean up test certificates after validation:

Terminal window
# Remove all test certificates (adjust thumbprints as needed)
Get-ChildItem Cert:\LocalMachine\My|Where-Object {$_.Subject -like "*Test*"}|Remove-Item -Force

Q: Certificate shows HasPrivateKey=True but monitoring reports missing private key
A: This can happen when the private key exists but is not accessible to the monitoring service account. Verify service account permissions to the private key.

Q: 1024-bit certificate doesn't trigger weak key warning
A: Check monitoring agent configuration for key strength policies. Some policies may be disabled by default.

Q: Exportable key detection not working
A: Exportable key detection requires specific permissions. Ensure monitoring service account can query certificate key properties.


Run PowerShell Scripts - Execute individual or batch testing scenarios
Verify Monitoring Results - Confirm expected certificate states in Nodinite
Clean Up Test Certificates - Remove test certificates after validation

Certificate Overview
Certificate Monitoring
Certificate Configuration
Private Key Health
FAQ: Certificates for gMSA Accounts

...

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...