Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
883 B
2
Indexable
Never
Import-Module DnsServer

# Get all DNS zones
$zones = Get-DnsServerZone

# Create an empty array to store all records
$allRecords = @()

# Iterate over each zone
foreach ($zone in $zones) {
    # Get all A records for the current zone
    $records = Get-DnsServerResourceRecord -ZoneName $zone.ZoneName -RRType A

    # Iterate over each A record
    foreach ($record in $records) {
        # Get the IP address associated with the A record
        $ipAddress = $record.RecordData.IPv4Address.IPAddressToString

        # Add record and IP address to the array
        $allRecords += [PSCustomObject]@{
            "ZoneName" = $zone.ZoneName
            "RecordType" = $record.RecordType
            "HostName" = $record.HostName
            "IPAddress" = $ipAddress
        }
    }
}

# Export all records to CSV
$allRecords | Export-Csv -Path "dns_records.csv" -NoTypeInformation
Leave a Comment