-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Get-PublishedTemplates #161
Closed
SamErde
wants to merge
10
commits into
jakehildreth:testing
from
SamErde:feature-get-published-templates
Closed
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
09568ff
Create Get-PublishedTemplates.ps1
SamErde 7c1d071
Merge branch 'testing' into feature-get-published-templates
jakehildreth f12361b
Merge branch 'TrimarcJake:main' into feature-get-published-templates
SamErde 2f312f4
Update Get-PublishedTemplates.ps1
SamErde b4eab30
Merge branch 'TrimarcJake:main' into feature-get-published-templates
SamErde d165866
Merge branch 'testing' into feature-get-published-templates
SamErde 18e95d4
Merge branch 'TrimarcJake:main' into feature-get-published-templates
SamErde ff6c6d7
Merge branch 'TrimarcJake:main' into feature-get-published-templates
SamErde d888525
Merge branch 'TrimarcJake:main' into feature-get-published-templates
SamErde aa30518
Merge branch 'testing' into feature-get-published-templates
jakehildreth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
function Get-PublishedTemplates { | ||
<# | ||
.SYNOPSIS | ||
Get published certificate templates from Active Directory. | ||
|
||
.DESCRIPTION | ||
Gets all templates from Active Directory and identifies which ones are published. | ||
|
||
.EXAMPLE | ||
Get-PublishedTemplates | ||
|
||
.NOTES | ||
If either of these flags are set, the template is considered published: | ||
|
||
- CT_FLAG_IS_CA (0x1): This bit indicates whether the template is for a Certification Authority (CA). If this bit is set, the template is considered published. | ||
- CT_FLAG_IS_DEFAULT (0x2): This bit indicates whether the template is a default template. If this bit is set, the template is also considered published. | ||
|
||
If pkiEnrollmentFlag has 0x10 (CT_FLAG_PUBLISH_TO_DS) set, the certificate is published to Active Directory. | ||
#> | ||
[CmdletBinding()] | ||
param () | ||
|
||
$ADSISearcher = [adsisearcher]'(objectClass=*)' | ||
$ADSISearcher.SearchRoot = [adsi]'LDAP://RootDSE' | ||
$ConfigurationNamingContext = $ADSISearcher.SearchRoot.Properties['configurationNamingContext'][0] | ||
|
||
# Set the [adsisearcher] filter, search root, and other options | ||
$ADSISearcher = [adsisearcher]'(objectClass=pKICertificateTemplate)' | ||
$ADSISearcher.SearchRoot = [ADSI]"LDAP://CN=Certificate Templates,CN=Public Key Services,CN=Services,$ConfigurationNamingContext" | ||
|
||
$Results = $ADSISearcher.FindAll() | ||
|
||
[array]$Templates = @() | ||
|
||
foreach ($item in $Results) { | ||
$Template = $item.GetDirectoryEntry() | ||
$TemplateName = $Template.Properties['Name'][0] | ||
$OID = $item.Properties['mspki-cert-template-oid'][0] | ||
$Flags = $Template.Properties['flags'][0] | ||
$EnrollmentFlag = $item.Properties['mspki-enrollment-flag'][0] | ||
$LastModified = $item.Properties['whenchanged'][0] | ||
$Revision = $item.Properties['Revision'][0] | ||
$MinorRevision = $item.Properties['mspki-template-minor-revision'][0] | ||
|
||
# Check if the template is published | ||
$IsPublished = (($Flags -band 0x1) -ne 0 -or ($Flags -band 0x2) -ne 0) -or ($EnrollmentFlag -band 0x10) | ||
|
||
$Templates += ( | ||
[PSCustomObject]@{ | ||
Name = $TemplateName | ||
OID = $OID | ||
Flags = $Flags | ||
EnrollmentFlag = $EnrollmentFlag | ||
IsPublished = $IsPublished | ||
LastModified = $LastModified | ||
Revision = $Revision | ||
MinorRevision = $MinorRevision | ||
} | ||
) | ||
} | ||
return $Templates | Where-Object {$_.IsPublished -eq $true} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your logic doesn't seem consistent with what's actually published, but it's very possible I'm missing something.
Your code returns this from my lab CA:

But the Certificate Templates list on my lab CA looks like this:

Which matches CA's object's

cetificateTemplates
attribute expanded:Note: The Certificate Templates pane shows the templates
displayName
attribute while the expandedcertificateTemplates
list shows thename
attribute.This function should be rewritten to see if the template name exists within the
certificateTemplates
attribute on anypKIEnrollmentService
object. We already collect the required attribute inGet-ADCSObject
, so I think you could:name
s from all the CA objects$PublishedTemplates
$PublishedTemplates -contains $TemplateName
$true
or$false
to enrich the template object as a custom attribute.Or whatever you want to do. You probably have a more elegant way of doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about de-duplicating the list and the possibility of different versions of a template being published on different CAs. Is that possible, and if so: does a published template on multiple CAs have the same OID for each instance, or a unique one per CA?
EDIT: I think I found that the answer is no to both questions. One version across all CAs and the same OID for the template on all CAs.