In the line:
if ($ADServerFQDN.NameHost) { $ServerName = $ADServerFQDN[0].NameHost } else {
When I tested I found:
$ADServerFQDN.NameHost is true but $ADServerFQDN[0].hostname is null and is the AAAA record
$ADServerFQDN[1].hostname is null and the A record
$ADServerFQDN[2].hostname is NOT null and is the first NS record and has a namehost value but not the FQDN of $computer, it is the FQDN of the first nameserver.
namehost only exists in NS records, not A or AAAA records
For that statement to work, you need to reference $ADServerFQDN[0].Name not .namehost.
if ($ADServerFQDN.NameHost) could probably reference .name or .namehost. I am not sure if it makes a difference.
The change that worked for me is:
if ($ADServerFQDN.Name) { $ServerName = $ADServerFQDN[0].Name } else {
However, I am not sure why that first check is there, the code after the else which finds the A record is probably the better way to find the FQDN of $computer but what you really need to look for are the answer records.
This might be a better way to find the FQDN of $computer, it will find the answer records to the DNS query and extract the FQDN from them.
Test-LDAP can't find any ports or the FQDN. I tracked this down to these lines in function Test-LDAP in ADEssentials.psm1:line 5858
In the line:
if ($ADServerFQDN.NameHost) { $ServerName = $ADServerFQDN[0].NameHost } else {
When I tested I found:
$ADServerFQDN.NameHost
is true but$ADServerFQDN[0].hostname
is null and is the AAAA record$ADServerFQDN[1].hostname
is null and the A record$ADServerFQDN[2].hostname
is NOT null and is the first NS record and has a namehost value but not the FQDN of $computer, it is the FQDN of the first nameserver. namehost only exists in NS records, not A or AAAA recordsFor that statement to work, you need to reference
$ADServerFQDN[0].Name
not .namehost. if ($ADServerFQDN.NameHost) could probably reference .name or .namehost. I am not sure if it makes a difference. The change that worked for me is:However, I am not sure why that first check is there, the code after the else which finds the A record is probably the better way to find the FQDN of $computer but what you really need to look for are the answer records.
This might be a better way to find the FQDN of $computer, it will find the answer records to the DNS query and extract the FQDN from them.
Ronald Schubot Western Michigan University