Created
January 13, 2020 15:00
-
-
Save Jonatantwn/8813f274f56e549b27c18a932b940c4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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-Object { $_.QueryType -eq 'NS' } | |
[PSCustomObject]@{ | |
Resolved = $true | |
Rmatch = $DomainName -match $Domainfinal | |
DomainName = $DomainName | |
Domainfinal = (Invoke-WebRequest -Uri $DomainName -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri -replace "https://" -replace "http://" -replace "www." -replace ".dk/", ".dk" -replace ".com/", ".com" | |
NameServer = $NSRecords.NameHost | |
'A-Record' = (Resolve-DnsName $DomainName -Type A).IPAddress | |
'MX-Record' = (Resolve-DnsName $DomainName -Type MX).NameExchange | |
Origin = $FileName | |
} | |
} catch { | |
[PSCustomObject]@{ | |
Origin = $FileName | |
Rmatch = $Rmatch | |
DomainName = $DomainName | |
Resolved = $false | |
NameServer = '?' | |
Domainfinal = '?' | |
'A-Record' = '?' | |
'MX-Record' = '?' | |
} | |
} | |
} | |
} | |
$myOutput | Select-Object Origin, Resolved, DomainName, | |
@{n='Domainfinal'; e={$_.'Domainfinal' -join ', '}}, | |
@{n='NameServer';e={$_.NameServer -join ', '}}, | |
@{n='Rmatch'; e={$_.'Rmatch' -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