Home > Net >  Resolve-DnsName does not always return correct type
Resolve-DnsName does not always return correct type

Time:03-10

I tried to make simple script that would tell me if a domain has an A,MX,SPF record and so on.

The script mostly does the following.

 If (Resolve-DnsName $TestDomain -Type A -Server '8.8.8.8') {
        [bool]$ATest = $true
    }
    Else {
        [bool]$ATest = $false
    }

The problem with the above command is it comes out to be true even though the type returned is a SOA record and not an A record.

The above command returns like this.

Resolve-DnsName 'TEST.<Blank>.COM' -TYPE 'A'


Name                        Type TTL   Section    PrimaryServer               NameAdministrator           SerialNumber
----                        ---- ---   -------    -------------               -----------------           ------------
<blank>.COM                   SOA  3600  Authority  <blank>              <blank>

How do I make a simple command that will tell me yes there is an A record. I want there to be a false for everything else ?

CodePudding user response:

You can filter & check the count

(Resolve-DnsName <blank>.COM -Type A -Server '8.8.8.8' -DnsOnly | ? { $_.Type -eq 'A' }).Count -gt 0
  • Related