Created
September 13, 2021 21:43
-
-
Save HarmJ0y/eb2d41b68cd62c8895a80ca4219bc0a6 to your computer and use it in GitHub Desktop.
DC Certificate Template Enumeration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Results = ([adsisearcher]"(&(objectCategory=computer)(userAccountControl:1.2.840.113556.1.4.803:=8192))").FindAll() | % { | |
$Entry = $_.GetDirectoryEntry() | |
$SAM = $Entry.samAccountName[0] | |
$DN = $Entry.distinguishedName[0] | |
try { | |
$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 @($Entry.userCertificate) | |
$Exp = $Cert.GetExpirationDateString() | |
$TemplateExt = $Cert.Extensions | Where-Object{ ( $_.Oid.FriendlyName -eq 'Certificate Template Name') } | Select-Object -First 1 | |
[pscustomobject] @{ | |
'SamAccountName'=$SAM | |
'DistinguishedName'=$DN | |
'Thumprint'=$Cert.Thumbprint | |
'Expiration'=$Cert.GetExpirationDateString() | |
'TemplateName'=$TemplateExt.Format(1) | |
} | |
} | |
catch { | |
Write-Warning "Error retrieving the certificate from DC '$DN' !" | |
} | |
} | |
$Results | fl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment