Skip to content

Instantly share code, notes, and snippets.

@Jonatantwn
Created January 8, 2020 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonatantwn/378d7c7b8be503bca223b6438014eb57 to your computer and use it in GitHub Desktop.
Save Jonatantwn/378d7c7b8be503bca223b6438014eb57 to your computer and use it in GitHub Desktop.
Powershell Lookup V1.0
$FileList = (Get-ChildItem 'C:\Users\jonat\Desktop\DNS PROCCESSING\Batchtest\*.txt').fullname
$myOutput = @() # Declare empty array
foreach ($FileName in $FileList) {
$myOutput += foreach ($DomainName in (Get-Content $FileName)) {
try {
$NSRecords = Resolve-DnsName $DomainName -Type NS -EA 1 | where { $_.QueryType -eq 'NS' }
[PSCustomObject]@{
Origin = $FileName
DomainName = $DomainName
Resolved = $true
NameServer = $NSRecords.NameHost
'A-Record' = (Resolve-DnsName $DomainName -Type A).IPAddress
'MX-Record' = (Resolve-DnsName $DomainName -Type MX).NameExchange
}
} catch {
[PSCustomObject]@{
Origin = $FileName
DomainName = $DomainName
Resolved = $false
NameServer = '?'
'A-Record' = '?'
'MX-Record' = '?'
}
}
}
}
$myOutput | select Origin, DomainName, Resolved,
@{n='NameServer';e={$_.NameServer -join ', '}},
@{n='A-Record'; e={$_.'A-Record' -join ', '}},
@{n='MX-Record'; e={$_.'MX-Record' -join ', '}} |
Export-Csv 'C:\Users\jonat\Desktop\DNS PROCCESSING\Output\result-export.csv' -NoType
# or
$myOutput | Out-GridView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment