Problem
Get-CertificateTemplate and several other template-related cmdlets have no -Server, -ComputerName, -Domain or similar parameter.
They always operate in the domain context of the currently logged-on user.
This limitation is especially painful in the very common enterprise design where:
- Admins manage from a dedicated Management Forest (admin / bastion forest with privileged accounts)
- The actual Enterprise CA / AD CS and Certificate Templates live in a separate Resource Forest
In this setup the administrator’s logon domain (Management Forest) is different from the domain that stores the Certificate Templates (Resource Forest). PSPKI therefore cannot retrieve or manage the correct templates.
Root Cause
The cmdlets rely on the global variable $PkiConfigContext, which is set once during module import in PSPKI.psm1:
$Domain = (Get-ADRootDSE).defaultNamingContext # ← NO -Server parameter!
$script:PkiConfigContext = "CN=Public Key Services,CN=Services,$Domain"
Get-CertificateTemplate.ps1 then uses:
$ldap = [ADSI]"LDAP://CN=Certificate Templates,$PkiConfigContext"
Broader issue in the underlying pkix.net library
The same root cause exists deeper in the .NET library (pkix.net). Multiple classes perform LDAP queries via RootDSE without any -Server or ConfigurationNamingContext parameter:
CertificateAuthority.cs → LoadDisplayName() (this causes issue #177: empty DisplayName in cross-forest)
CertificateTemplate.cs → constructor / Refresh()
OcspResponder.cs → LoadFromAD()
NDES.cs → several AD queries
This is a systemic design issue across the entire library, not just the PowerShell layer.
Affected cmdlets (all use $PkiConfigContext)
| Cmdlet |
Uses $PkiConfigContext |
Notes |
Get-CertificateTemplate |
Yes |
Main cmdlet |
Get-ADKRACertificate |
Yes |
KRA certificates |
Get-CertificateTemplateAcl |
Yes |
Read ACLs |
Set-CertificateTemplateAcl |
Yes |
Modify ACLs |
Add-CertificateTemplateAcl |
Yes |
Add permissions |
Remove-CertificateTemplateAcl |
Yes |
Remove permissions |
Expected behavior
Native support like the CA cmdlets already have:
Get-CertificateTemplate -Server dc-adcs.resourceforest.local
Connect-CertificationAuthority -ComputerName "ca01.resourceforest.local" -Server dc-adcs.resourceforest.local
Clean workaround (when running on a machine in the Resource Forest)
function Get-CertificateTemplateFromLocalMachineDomain {
param([string]$DisplayNameLike = "*Web Server*")
$DomainName = (Get-ADDomain -Current LocalComputer).DNSRoot
Get-ADObject -LDAPFilter "(displayName=$DisplayNameLike)" `
-SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,$((Get-ADRootDSE -Server $DomainName).configurationNamingContext)" `
-Server $DomainName `
-Properties Name, DisplayName, DistinguishedName
}
Problem
Get-CertificateTemplateand several other template-related cmdlets have no-Server,-ComputerName,-Domainor similar parameter.They always operate in the domain context of the currently logged-on user.
This limitation is especially painful in the very common enterprise design where:
In this setup the administrator’s logon domain (Management Forest) is different from the domain that stores the Certificate Templates (Resource Forest). PSPKI therefore cannot retrieve or manage the correct templates.
Root Cause
The cmdlets rely on the global variable
$PkiConfigContext, which is set once during module import inPSPKI.psm1:Get-CertificateTemplate.ps1then uses:Broader issue in the underlying pkix.net library
The same root cause exists deeper in the .NET library (
pkix.net). Multiple classes perform LDAP queries viaRootDSEwithout any-ServerorConfigurationNamingContextparameter:CertificateAuthority.cs→LoadDisplayName()(this causes issue #177: emptyDisplayNamein cross-forest)CertificateTemplate.cs→ constructor /Refresh()OcspResponder.cs→LoadFromAD()NDES.cs→ several AD queriesThis is a systemic design issue across the entire library, not just the PowerShell layer.
Affected cmdlets (all use $PkiConfigContext)
Get-CertificateTemplateGet-ADKRACertificateGet-CertificateTemplateAclSet-CertificateTemplateAclAdd-CertificateTemplateAclRemove-CertificateTemplateAclExpected behavior
Native support like the CA cmdlets already have:
Clean workaround (when running on a machine in the Resource Forest)