title: Generate list of all DNS records in specified subnet
body: <p>I need to generate a list of all DNS records for a specified subnet. Is there a way to do this using either the powershell DNS cmdlets, DNSCMD, or anything else, that isn't the very slow way that I am currently using? </p>
  
  <p>I'm enumerating the host names in <code>17.(7,8,9).162.(16-238)</code>.</p>
  
  <pre><code>$HostList = @()
  
  ForEach ($a in 7..9) { 
      ForEach ($b in 16..238) {
          $DNSCheck = Resolve-DNSName "17.$a.162.$b"
          $HostList += ($DNSCheck.NameHost)
      }
  }
  
  Write-Host $HostList
  </code></pre>
  
  <p>What I've ended up using - Many thanks to Ansgar.</p>
  
  <pre><code>$ZoneName = "some.domain"
  $DNSHost = "dnsserver"
  
  $Hosts = Get-DnsServerResourceRecord $ZoneName -ComputerName $DNSHost -RRType 'A' |? { 
      $Address = $_.RecordData.IPV4Address.ToString()
      $LastOctet = $Address.Split(".")[-1]
      $Address -like "17.[7-9].162.*" -and $LastOctet -in 16..238
  }
  
  ForEach ($H in $Hosts) {
      Write-Host $H.HostName
  }
  </code></pre>