Get-CertificateAuthority.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
function Get-CertificatAuthority { <# .Synopsis Get list of Certificate Authorities from Active directory .DESCRIPTION Queries Active Directory for Certificate Authorities with Enrollment Services enabled .EXAMPLE Get-CertificatAuthority .EXAMPLE Get-CertificatAuthority -CaName 'MyCA' .EXAMPLE Get-CertificatAuthority -ComputerName 'CA01' -Domain 'Contoso.com' .OUTPUTS System.DirectoryServices.DirectoryEntry #> [CmdletBinding()] [OutputType([adsi])] Param ( # Name given when installing Active Directory Certificate Services [string[]] $CAName = $null, # Name of the computer with Active Directory Certificate Services Installed [string[]] $ComputerName = $null, # Domain to Search [String] $Domain = (Get-Domain).Name ) Write-Verbose $Domain ## If the DN path does not exist error message set as valid object $CaEnrolmentServices = Get-ADPKIEnrollmentServers $Domain $CAList = $CaEnrolmentServices.Children if($CAName) { $CAList = $CAList | Where-Object -Property Name -In -Value $CAName } if ($ComputerName) { # Make FQDN [Collections.ArrayList]$List = @() foreach ($Computer in $ComputerName) { if ($Computer -like "*.$Domain") { $null = $List.add($Computer) } else { $null = $List.add("$($Computer).$Domain") } } # end foreach $CAList = $CAList | Where-Object -Property DNSHostName -In -Value $List } $CAList } |