Find Pointer Records in bulk by PowerShell Script

Опубликовано: 04 Август 2026
на канале: BineshTech
4
0

Define the paths for your input and output files
$InputFile = "C:\temp\IPAddresses.txt"
$OutputFile = "C:\temp\PointerRecords.csv"

Check if the input file exists before continuing
if (-not (Test-Path -Path $InputFile)) {
Write-Error "Input file not found at $InputFile"
exit
}

Read the IP addresses from the text file
$IPList = Get-Content -Path $InputFile

Iterate through each IP and perform a reverse DNS lookup
$Results = foreach ($IP in $IPList) {
Skip empty lines or spaces in the text file
if ([string]::IsNullOrWhiteSpace($IP)) { continue }

Write-Host "Resolving PTR record for: $IP..." -ForegroundColor Cyan

try {
Query for the PTR record
$DnsRecord = Resolve-DnsName -Name $IP -Type PTR -ErrorAction Stop

Output custom object properties
[PSCustomObject]@{
IPAddress = $IP
PTRName = $DnsRecord.Name
HostName = $DnsRecord.NameHost
Status = "Success"
}
}
catch {
Catch failed or non-existent reverse DNS lookups
[PSCustomObject]@{
IPAddress = $IP
PTRName = "N/A"
HostName = "N/A"
Status = "Failed: $($_.Exception.Message)"
}
}
}

Export the compiled array to a CSV file
$Results | Export-Csv -Path $OutputFile -NoTypeInformation
Write-Host "Process complete! Results exported to: $OutputFile" -ForegroundColor Green