PowerShell - Get All Zone Information in DNS
- Jon Boyette
- Jan 25, 2022
- 1 min read
Save below as a self named .ps1 or copy and paste, this give ALL DNS information with the domain it is ran on, hostname, recordtypes, zonename and data outputs to screen
#
# Get all zone information for a Domain Zone
#
$zone = 'salelytics.local'
Get-DnsServerResourceRecord -Zonename $zone -ComputerName 1150749-dc1 | Select-Object hostname, recordType, @{n='ZoneName';Expression={$zone}},@{n='Data';e={
$rr = $_
switch ($rr.RecordType) {
'A' {$rr.RecordData.IPv4Address}
'CNAME' {$rr.RecordData.HostnameAlias}
'NS' {$rr.RecordData.NameServer}
'SOA' {$rr.RecordData.PrimaryServer}
'SRV' {$rr.RecordData.DomainName}
'PTR' {$rr.RecordData.PtrDomainName}
'MX' {$rr.RecordData.MailExchange}
'AAAA' {$rr.RecordData.IPv6Address}
'TXT' {$rr.RecordData.DescriptiveText}
}
}}
Comments