Validate-LDAPSBinding.ps1


Description

Purpose

No synopsis provided.

Detailed Description

No detailed description provided.

Back to Top

Usage

No usage examples provided.

Back to Top

Notes

No additional notes.

Back to Top


Script

function Validate-LDAPSBinding {
    param (
        [Parameter(Mandatory=$true)]
        [string]$DomainControllerFQDN,
        
        [Parameter(Mandatory=$true)]
        [string]$CertThumbprint,
        
        [Parameter(Mandatory=$true)]
        [pscredential]$Credential
    )

    $scriptBlock = {
        param (
            [string]$DomainControllerFQDN,
            [string]$CertThumbprint
        )

        $result = [PSCustomObject]@{
            DomainControllerFQDN = $DomainControllerFQDN
            CertThumbprint       = $CertThumbprint
            LDAPSEnabled         = $false
            CertificateBound     = $false
            Message              = ""
        }

        Write-Verbose "Validating LDAPS settings on $DomainControllerFQDN"

        # Check registry settings
        $ldapsAuthentication = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters" -Name "ClientLDAPSAuthentication" -ErrorAction SilentlyContinue
        $ldaps = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters" -Name "ClientLDAPS" -ErrorAction SilentlyContinue

        if ($ldapsAuthentication -and $ldaps) {
            if ($ldapsAuthentication.ClientLDAPSAuthentication -eq 1 -and $ldaps.ClientLDAPS -eq 1) {
                $result.LDAPSEnabled = $true
            }
        }

        # Check if the certificate is bound
        $store = [System.Security.Cryptography.X509Certificates.X509Store]::new("NTDS", "LocalMachine")
        $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
        $cert = $store.Certificates | Where-Object {
            $_.Thumbprint -eq $CertThumbprint
        }
        if ($cert) {
            $result.CertificateBound = $true
            $result.Message = "LDAPS is correctly configured on $DomainControllerFQDN with certificate $CertThumbprint"
        } else {
            $result.Message = "LDAPS is not correctly configured on $DomainControllerFQDN. Certificate $CertThumbprint is not bound."
        }
        $store.Close()

        return $result
    }

    $validationResult = Invoke-Command -ComputerName $DomainControllerFQDN -ScriptBlock $scriptBlock -ArgumentList $DomainControllerFQDN, $CertThumbprint -Credential $Credential -Verbose
    return $validationResult
}

# Example usage of the function:
# $validationResult = Validate-LDAPSBinding -DomainControllerFQDN "RDGDC01.rdg.co.uk" -CertThumbprint "9f580f463113ea7615847821ad3775d690c640d2" -Credential (Get-Credential) -Verbose
# $validationResult | Format-List

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top