AD.Servers.psm1

function Confirm-PrincipalsAllowedToRetrieveManagedPassword {
    [CmdletBinding()]
    [OutputType('System.Boolean')]
    param(
        [Parameter(Mandatory = $true)]
        [System.Collections.CollectionBase]$Principals,
        [Parameter(Mandatory = $true)]
        [String[]]$Servers
    )
    # Validate Count
    if([array]$Principals.count -ne $Servers.count){
        Write-Warning "Expected: $($Servers.count) servers, found $([array]$Principals.count)"
        Return $false
    }

    # Validate each server
    foreach ($server in $Servers) {
        $found = $false

        foreach($Principal in $Principals){
            if($Principal.StartsWith("CN=$server,")){
                $found = $true
                break;
            }
        }
        if($found -eq $false){
            Write-Warning "Missing server: $server"
            return $false
        }
    }

    # Count matches and servers all found
    Return $true
}