Private/Get-ADCSEnrollmentServices.ps1

<#
.SYNOPSIS
Lists Active Directory Certificate Services enrollment services.
 
.DESCRIPTION
Queries enrollment service objects and reports server reachability and assigned certificate
templates.
 
.COMPONENT
Category: Sub Function
 
.FUNCTIONALITY
Reports enrollment servers, reachability, and whether certificate templates are assigned.
#>

function Get-ADCSEnrollmentServices {

    ################################################################################
    ##### #####
    ##### Get all Enrollment Services #####
    ##### #####
    ################################################################################

    Param(
        [Parameter(ValueFromPipeline, Mandatory)]
        [string]$Server    
    )

    $Info = Measure-FunctionRuntime -Begin

    $ConfigNC = (Get-ADRootDSE).ConfigurationNamingContext
    $caenrolls = Get-ADObject -LDAPFilter "(objectClass=pKIEnrollmentService)" `
        -SearchBase "CN=Public Key Services,CN=Services,$ConfigNC"  `
        -Properties Name, dNSHostName, certificateTemplates, flags   `
        -Server $Server

    Write-AS2GoOutput -Type H1 -Message "Identitfied Web Enrollment Services CAs"


    If ($null -ne $caenrolls) {
        $caenrolls | Select-Object Name, 
        dNSHostName, 
        @{N = 'Online'; E = { Test-Connection -ComputerName $_.dNSHostName -Count 1 -Quiet -ErrorAction SilentlyContinue } },
        @{N = 'HasTemplates'; E = { $_.certificateTemplates.Count -gt 0 } }, 
        @{N = 'Templates'; E = { $_.certificateTemplates.Count } } |  Format-Table
        $Script:ADCSEnrollmentServiceMissing = $false
    }
    else {
        Write-AS2GoOutput -Type Info -Message "No pKIEnrollmentService found."
    }

    
    $4logfile = $caenrolls | Select-Object Name, 
    dNSHostName, 
    @{N = 'Online'; E = { Test-Connection -ComputerName $_.dNSHostName -Count 1 -Quiet -ErrorAction SilentlyContinue } },
    @{N = 'HasTemplates'; E = { $_.certificateTemplates.Count -gt 0 } }, 
    @{N = 'Templates'; E = { $_.certificateTemplates.Count } } | Format-Table | out-string 
    Write-Log -Message " >> Identified the following Web Enrollment Services in Forest '$ConfigNC': $4logfile"
  
    Measure-FunctionRuntime -End -Details $Info
}