#Requires -Modules DnsClient-PS
function DnsResolveHost {
   param(
    [Parameter(Mandatory)]
    [string] $domainName,
    [Parameter(Mandatory)]
    [string] $effectoryDomainPattern,
    [Parameter()]
    [string] $externalDNSServer = "8.8.8.8"
)

    try {

        $CnameChain = Resolve-Dns -query $domainName -QueryType A -NameServer $externalDNSServer -ContinueOnDnsError -ContinueOnEmptyResponse
        $CnameChain.AllRecords.Where({$_.DomainName.Value -notlike "$($effectoryDomainPattern)."}, 'First').DomainName.Value
    }
    catch {
        $null
    }

    
}