10th November 2021
Resolve-DNSName from list
A Colleague needed a script to check a list of ip-addresses or computername against the DNS and i created this script.
You need a txt-file with what you want to check against the DNS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
######################################################### #.Synopsis # Read txt-file and run multiple check on DNS #.DESCRIPTION # The script import a txt-file with multiple values to check against DNS #.EXAMPLE # Get-DNSRecords.ps1 -List .\textfile.txt # # Txt-file strukture:(No header!) # # dc01 # 192.168.3.214 # # Result on screen: # # Result Data # ------ ---- # 192.168.3.200 dc01.corp.viamonstra.com # CM01.corp.viamonstra.com 192.168.3.214 # # Skript created by Christian Damberg # christian@damberg.org # https://www.damberg.org # # Scriptversion 1.0 # 2021-11-09 # ######################################################### param ($List) $ListToCheck = Get-Content $list $Result = @() foreach ($item in $ListToCheck) { $communication = Test-Connection $item -Count 1 -Quiet if ($communication -eq $true) { $GetDnsType = Resolve-DnsName $item $DnsType = $GetDnsType.type if ($DnsType -eq 'A') { $data = Resolve-DnsName $item -Type A $props = @{ 'Result'=$data.IPAddress 'Data'=$data.Name } } else { $data = Resolve-DnsName $item $props = @{ 'Result'=$data.NameHost 'Data'=$item } } $obj = New-Object -TypeName PSobject -Property $props $Result += $obj } else { $props = @{ 'Result'='No response' 'Data'=$item } $obj = New-Object -TypeName PSobject -Property $props $Result += $obj } } $Result | Format-Table |
If you want to download it, here´s the link