Private/PublishCert.ps1
Function PublishCert { Param ( $CertDisplayName ) #Publish Template #grab DC $Server = (Get-ADDomainController -Discover -ForceDiscover -Writable).HostName[0] #grab Naming Context $ConfigNC = (Get-ADRootDSE -Server $Server).configurationNamingContext ### WARNING: Issues on all available CAs. Test in your environment. $EnrollmentPath = "CN=Enrollment Services,CN=Public Key Services,CN=Services,$ConfigNC" $CAs = Get-ADObject -SearchBase $EnrollmentPath -SearchScope OneLevel -Filter * -Server $Server ForEach ($CA in $CAs) { Set-ADObject -Identity $CA.DistinguishedName -Add @{certificateTemplates=$CertDisplayName.Replace(' ','')} -Server $Server } } |