Automated deployment scripts for building a Microsoft PKI 2-tier infrastructure (Root CA + Enterprise Subordinate CA) on Windows Server Core.
This project provides PowerShell scripts to automate the deployment of a complete Microsoft PKI infrastructure in approximately 15 minutes. Designed for organizations that need to quickly establish PKI for:
- LDAPS (LDAP over SSL/TLS)
- Certificate-based authentication
- Code signing
- Document signing
- Email encryption
- VPN certificates
- And other certificate-based security solutions
After working on ransomware recovery and infrastructure improvements, I noticed that PKI infrastructure is consistently missing at customer locations. This project was created to fill that gap with a reliable, automated solution.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Root CA (Offline) β
β - Standalone CA (not domain-joined) β
β - Valid for 10 years β
β - Only online during SubCA installation β
β - Taken offline after deployment β
βββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β Issues certificate to
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Enterprise Subordinate CA (Online) β
β - Domain-joined Enterprise CA β
β - Valid for 5 years β
β - Issues certificates to domain members β
β - Valid for 1 year (configurable) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- β Automated deployment - Minimal manual intervention
- β Server Core optimized - Designed for headless deployment
- β Security best practices - SHA-384, 4096-bit keys, proper CRL configuration
- β Comprehensive logging - Full audit trail
- β Post-installation validation - Ensures proper configuration
- β Backup automation - Secure backup of CA keys
- β Windows Server 2025 compatible - Tested on all modern Windows Server versions
-
Obtain an OID (Object Identifier)
- Register at: https://pen.iana.org/pen/PenApplication.page
- You'll receive a 5-digit PEN (Private Enterprise Number)
- This is required for the CA policy OID
-
DNS Configuration
- Create a DNS CNAME record (e.g.,
pki.company.com) pointing to your Enterprise Subordinate CA server - This will be used for CRL and AIA distribution points
- Create a DNS CNAME record (e.g.,
-
Server Requirements
-
Root CA Server:
- Windows Server 2012/2016/2019/2022/2025 (Server Core recommended)
- NOT domain-joined (standalone/workgroup)
- Administrator access
- Network connectivity (temporary, for SubCA installation)
-
Subordinate CA Server:
- Windows Server 2012/2016/2019/2022/2025 (Server Core recommended)
- Domain-joined (required for Enterprise CA)
- Domain administrator access
- Network connectivity to Root CA
-
-
Network Configuration
- Both servers need network connectivity during deployment
- Root CA can be disconnected after SubCA installation completes
- Ensure firewall allows PSRemoting (WinRM) between servers
- Deploy two Windows Server Core instances
- Configure IP addresses and basic networking
- Root CA: Ensure it's NOT domain-joined
- SubCA: Ensure it's domain-joined and you're logged in with a domain account
# On Root CA server (not domain-joined)
.\Build-RootCA.ps1Script Parameters:
-EnablePSRemoting- Enable PSRemoting (default: enabled, required for SubCA)-CreateBackup- Automatically create backup after installation-BackupPath- Custom backup path (default:SystemDrive\CA-Backup)
Example with backup:
.\Build-RootCA.ps1 -CreateBackup# On SubCA server (domain-joined, domain admin account)
.\Build-SubCA.ps1- Verify SubCA installation completed successfully
- Take Root CA offline:
- Disable network adapters
- Disable PSRemoting
- Shutdown and store securely
- Verify certificate issuance from SubCA
The Root CA script will prompt you for:
- CA Common Name (e.g.,
Corp-Root-CA) - OID (5-digit number from IANA)
- CRL URL (e.g.,
pki.company.com)
Security Configuration (Hardcoded):
- Hash Algorithm: SHA-384
- Key Length: 4096 bits
- CA Validity: 10 years
- CRL Period: 1 year
- Certificate Validity: 1 year
What the Script Does:
- β Validates prerequisites (admin rights, Windows Server, not domain-joined)
- β Enables PSRemoting (required for SubCA connection)
- β Creates CAPolicy.inf with security settings
- β Installs ADCS-Cert-Authority feature
- β Installs Standalone Root CA
- β Configures CRL distribution points
- β Configures AIA entries
- β
Creates CertConfig share (
\\RootCA\CertConfig) - β Publishes initial CRL
- β Validates CA configuration
- β Optionally creates backup
Important Notes:
β οΈ Root CA must remain ONLINE during SubCA installationβ οΈ PSRemoting is required - The SubCA script connects via PSRemotingβ οΈ Scripts must run LOCALLY - Not through remote PowerShell
The SubCA script will:
- Connect to Root CA via PSRemoting
- Submit certificate request
- Retrieve signed certificate
- Install Enterprise Subordinate CA
- Configure CRL and AIA distribution points
The Root CA is designed to be offline after deployment:
-
During Deployment:
- Network connectivity required
- PSRemoting enabled
- CertConfig share accessible
-
After Deployment:
- β Disable all network adapters
- β Disable PSRemoting
- β Disable unnecessary services
- β Enable BitLocker (if supported)
- β Store in physically secure location
- β Create and verify backups
-
When to Bring Online:
- SubCA certificate renewal
- Root CA certificate renewal
- SubCA certificate revocation
- CRL updates
-
Strong Cryptography:
- SHA-384 hash algorithm
- 4096-bit RSA keys
- Proper certificate validity periods
-
CRL Configuration:
- Annual CRL publication
- Weekly delta CRL
- 2-week CRL overlap period
-
Audit and Logging:
- Comprehensive file-based logging
- All CA operations audited
- Full deployment audit trail
| Certificate Type | Validity Period | Notes |
|---|---|---|
| Root CA | 10 years | Hardcoded in script |
| Subordinate CA | 5 years | Configured during SubCA installation |
| Issued Certificates | 1 year | Configurable (1-2 years recommended) |
Solution: Ensure the Root CA server is in a workgroup, not joined to a domain.
Solution: The Root CA script enables PSRemoting by default. If disabled, run:
Enable-PSRemoting -ForceSolution:
- Verify Root CA is online and accessible
- Check firewall rules (WinRM port 5985/5986)
- Verify CertConfig share is accessible:
\\RootCA\CertConfig - Test PSRemoting:
Test-WSMan -ComputerName RootCA
Solution: Ensure you enter exactly 5 digits (your IANA PEN number).
Solution: The script will prompt to overwrite. Choose 'y' if you want to update it.
Log files are automatically created in:
C:\ProgramData\PKI\Logs\RootCA-Build-YYYYMMDD-HHMMSS.log
Check these logs for detailed error information.
| Parameter | Type | Default | Description |
|---|---|---|---|
-EnablePSRemoting |
Switch | Enabled | Enable PSRemoting (required for SubCA) |
-CreateBackup |
Switch | Disabled | Automatically create backup after installation |
-BackupPath |
String | SystemDrive\CA-Backup |
Custom backup path |
Example:
.\Build-RootCA.ps1 -CreateBackup -BackupPath "D:\CA-Backup"See script help for SubCA parameters:
Get-Help .\Build-SubCA.ps1 -Full- Simplified parameters (3 instead of 14)
- Hardcoded secure defaults
- Optimized for single-use deployment
- Server Core friendly
- File-based logging
- Post-installation validation
- Automated CertConfig share
- Progress indicators
- HSM support
- Configuration export/import
- Security enhancements (SHA-384, proper CRL periods)
- Domain-joined validation
- Network isolation checks
- Automated backup
- Verify CA installation completed successfully
- Verify backup created and tested
- Verify CertConfig share is accessible
- Verify PSRemoting is enabled
- Take VM snapshot (if virtualized)
- Proceed with SubCA installation
- After SubCA installation: Disable PSRemoting
- After SubCA installation: Disable network adapters
- After SubCA installation: Store server securely
- Verify SubCA installation completed successfully
- Verify certificate issuance works
- Verify CRL distribution points are accessible
- Verify AIA entries are accessible
- Test certificate enrollment
- Document CA configuration
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License.
Marc Bouchard
- Created: 2021/03/04
- Last Updated: 2024/12/19
- Version: 3.1
- These scripts must be run LOCALLY on the servers, not through remote PowerShell
- Root CA must remain ONLINE during SubCA installation
- PSRemoting is required for SubCA to connect to Root CA
- Backup is critical - Always create backups before taking Root CA offline
- Test in a lab environment before deploying to production
For issues, questions, or contributions:
- Open an issue on GitHub
- Review the troubleshooting section above
- Check log files for detailed error information
Deploy a complete PKI infrastructure in 15 minutes! π